Skip to content

Instantly share code, notes, and snippets.

@matt-42
Created June 15, 2012 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-42/2936289 to your computer and use it in GitHub Desktop.
Save matt-42/2936289 to your computer and use it in GitHub Desktop.
strcmp string comparison
#include <iostream>
#include <cstring>
double get_time()
{
timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return double(ts.tv_sec) + double(ts.tv_nsec) / 1000000000.;
}
int main()
{
const unsigned n = 1000000;
double t = get_time();
int k;
for (unsigned i = 0; i < n; i++)
strcmp("string", "string");
std::cout << get_time() -t << std::endl;
t = get_time();
}
./a.out
0.00040102 (seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment