SPO Project Update

Today I started to write out how I am gonna optimize my function strcspn, atm I’ve written a Tester and wrote my first version of the code. Atm, I’m trying to figure out how to avoid using a nested for loop, but it is a start none the less!

size_t STRCSPN_JJ(const char* str, const char* reject) {
const char *p, *q;

#ifdef __OPTIMIZE__
if (inside_main)
abort();
#endif

for (p = str; *p; p++) {
for (q = reject; *q; q++) {
if (*p == *q)
return p – str;

}
}

return -1;

}

Atm,. this is a lot slower than the gnu library function but I still feel like I can improve the function!

Here is what the tester I made had to say: entry three is my function

35f8fab10e12f09d73ee3dfa1b45bdf6.png

As you can see when we get up to a 900 array my function gets slower, while the other 2 stay as 0 milliseconds, mine went up to 2 milliseconds. So I’m still gonna have to figure out how I can fix this. I am hopeful to find a solution. At least on the upside, my function return the correct iteration!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s