Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6612673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:07:34+00:00 2026-05-25T20:07:34+00:00

I have a file that’s 21056 bytes. I’ve written a program in C that

  • 0

I have a file that’s 21056 bytes.

I’ve written a program in C that reads the entire file into a buffer, and then uses multiple search algorithms to search the file for a token that’s 82 chars.

I’ve used all the implementations of the algorithms from the “Exact String Matching Algorithms” page. I’ve used: KMP, BM, TBM, and Horspool. And then I used strstr and benchmarked each one.

What I’m wondering is, each time the strstr outperforms all the other algorithms. The only one that is faster sometimes is BM.

Shouldn’t strstr be the slowest?

Here’s my benchmark code with an example of benchmarking BM:

double get_time()
{
    LARGE_INTEGER t, f;
    QueryPerformanceCounter(&t);
    QueryPerformanceFrequency(&f);
    return (double)t.QuadPart/(double)f.QuadPart;
}
before = get_time();
BM(token, strlen(token), buffer, len);
after = get_time();
printf("Time: %f\n\n", after - before);

Could someone explain to me why strstr is outperforming the other search algorithms? I’ll post more code on request if needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:07:35+00:00Added an answer on May 25, 2026 at 8:07 pm

    Why do you think strstr should be slower than all the others? Do you know what algorithm strstr uses? I think it’s quite likely that strstr uses a fine-tuned, processor-specific, assembly-coded algorithm of the KMP type or better. In which case you don’t stand a chance of out-performing it in C for such small benchmarks.

    (The reason I think this is likely is that programmers love to implement such things.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that was written with the following Delphi declaration ... Type
I have a file that describes input data, which is split into several other
I have a file that I read into a char array. The char array
I have a file that reads like this 2012-021 24X7 Online Tutoring Company Applied
I have a file that I've been working on and then realized that I
I have ini file that I read in my program. The ini file need
I have a file that is organized into columns, with data that needs to
I have a file that needs to be refreshed every days, linked into a
I have a file that I want to include in Python but the included
I have a file that lists filenames, each on it's own line, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.