Skip to content

Instantly share code, notes, and snippets.

@lsegal
Created September 1, 2009 22:40
Show Gist options
  • Save lsegal/179437 to your computer and use it in GitHub Desktop.
Save lsegal/179437 to your computer and use it in GitHub Desktop.
// Benchmark with Clang
void benchmark(char *name, size_t times, void (^block)(void)) {
size_t i;
clock_t t1, t2;
t1 = clock();
for (i = 0; i < times; i++) block();
t2 = clock();
float diff = ((float)t2 - (float)t1) / (float)CLOCKS_PER_SEC;
printf("- %s took %.4f seconds\n", name, diff);
}
int main() {
benchmark("hello", 1000, ^{
int i = rand() * 10;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment