Created
September 1, 2009 22:40
-
-
Save lsegal/179437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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