0

When I run my speller program, everything compiles fine and the results are accurate, but the check function seems to be way too slow (takes ~7seconds) compared to staff's version(~0.2 seconds) and so my program did not qualify for the Big Board. All other functions run as fast as the staff's. If anyone notices anything that is causing this delay, I would love to hear your thoughts. thank you!

Here are my results vs. the staff solution's :

Mine:

WORDS IN DICTIONARY:  143091
WORDS IN TEXT:        17756
TIME IN load:         0.02
TIME IN check:        7.00
TIME IN size:         0.00
TIME IN unload:       0.00
TIME IN TOTAL:        7.02

Staff's:

WORDS IN DICTIONARY:  143091
WORDS IN TEXT:        17756
TIME IN load:         0.02
TIME IN check:        0.01
TIME IN size:         0.00
TIME IN unload:       0.01
TIME IN TOTAL:        0.05

And here is my check function:

bool check(const char *word)
{
    //hash word to obtain index for that word
    int index = hash(word);

    //access linked list at the index in the hash table and
    //traverse linked list, looking for the word
    node *cursor = table[index];
    while (cursor != NULL)
    {
        if (strcasecmp(word, cursor->word) == 0)
        {
            return true;
        }

        cursor = cursor->next;
    }
    return false;
}
1

I'm going to suggest that you go to this web site and look at the times posted by "competitors". ;-)

https://speller.cs50.net/cs50/problems/2020/x/challenges/speller

At 7 seconds, that's a pretty good run time. You're now asking everyone to give you hints on how to set record speeds and place higher on the challenge board!!!! I'm not sure that's a fair thing to do! :-D

Now, if it's taking 7 seconds for the small file as input, that's another story.

Anyways, that's my thought on it. Good luck improving your speed!!!! ;-)

[EDIT] But I will give you these hints. Increased performance usually comes from tuning load and hash, as well as check, not just check.

| improve this answer | |
  • Unfortunately, my run time was 7 seconds when the input file was small, not when I tried to submit for the Big Board like the link you shared. – sonwy102 May 22 at 23:08
  • WORDS IN DICTIONARY: 143091 WORDS IN TEXT: 17756 ------- no, this is a full run. Your times may be a little slow by comparison, but it's reasonable. Keep in mind that the staff version has some high speed tricks buried in the code. Your challenge is to match their speed! When I said small, I meant a test file with maybe a dozen words or less. Keep in mind that your run time can also be affected by system load. How many other people are running software on the server at the same time? Good luck! ;-) – Cliff B May 22 at 23:44
  • Also, the runs on the big board are running a more complex input data set. Have you submitted your code to the challenge board? What were your times when submitted? Also, see my edited answer. – Cliff B May 22 at 23:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .