1

I'm doing our homework... And I found that my code work slower than my classmate's.

Spending some time seeing what's different between our code, I found my load file work much slower than his. He use regex to parse string

The buckets.in and homework spec can be download here http://cial.csie.ncku.edu.tw/course/2013_Fall_Programming/download/hw4.rar

This is my original code http://codepad.org/7atC1hY9

my code with my classmate's inputting method http://codepad.org/jNfqr5Mc

See line 94

//Parse it with space
char *p=strtok(buffer, " ");
while(p!=NULL){
    if(*p!='\n'&&*p!='\0')
        buckets[count].data[buckets[count].N++]=atoi(p);
    p=strtok(NULL, " ");
}

vs

for(;sscanf(buffer, "%d %[1234567890 ]", &buckets[count].data[buckets[count].N], buffer)>1;buckets[count].N++);

This is my classmate's code http://codepad.org/MMI18Dlz

Also, it seems he did not do anything do improve performance on bucket mapping, but it just run a lot faster than mine. (maybe n is too small...)

4

0 回答 0