Skip to content
Browse files

Add benchmark

  • Loading branch information...
1 parent 76726e1 commit a8af35d83651ee9a61e7a6ea8f1c589ebc125edf Fuji Goro committed Sep 2, 2011
Showing with 60 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +6 −0 Makefile
  3. +53 −0 benchmark.cpp
View
1 .gitignore
@@ -3,4 +3,5 @@
*.dSYM
*.swp
test
+benchmark
View
6 Makefile
@@ -3,3 +3,9 @@ test: fast_strtox.h test.cpp
g++ -O3 test.cpp -o test
./test
+benchmark: fast_strtox.h benchmark.cpp
+ g++ -O3 benchmark.cpp -o benchmark
+ ./benchmark
+ clang++ -O3 benchmark.cpp -o benchmark
+ ./benchmark
+
View
53 benchmark.cpp
@@ -0,0 +1,53 @@
+#include <boost/timer.hpp>
+#include <cstdlib>
+#include <iostream>
+
+#include "fast_strtox.h"
+
+#undef strtof
+#undef strtod
+#undef strtol
+
+int main() {
+ const char* const pistr = "3.14159265358979323846264338327950288,foo";
+ const char* const ansstr = "42,foo";
+ {
+ boost::timer t;
+ for(int i = 0; i < (1 * 1000 * 1000); ++i) {
+ char* tmp;
+ float f = std::strtof(pistr, &tmp);
+ (void)f;
+ }
+ std::cout << "std::strtof(): " << t.elapsed() << std::endl;
+ }
+ {
+ boost::timer t;
+ for(int i = 0; i < (1 * 1000 * 1000); ++i) {
+ char* tmp;
+ float f = fast_strtof(pistr, &tmp);
+ (void)f;
+ }
+ std::cout << "fast_strtof(): " << t.elapsed() << std::endl;
+ }
+ {
+ boost::timer t;
+ for(int i = 0; i < (1 * 1000 * 1000); ++i) {
+ char* tmp;
+ float f = std::strtol(ansstr, &tmp, 10);
+ (void)f;
+ }
+ std::cout << "std::strtol(): " << t.elapsed() << std::endl;
+ }
+ {
+ boost::timer t;
+ for(int i = 0; i < (1 * 1000 * 1000); ++i) {
+ char* tmp;
+ float f = fast_strtol(ansstr, &tmp, 10);
+ (void)f;
+ }
+ std::cout << "fast_strtol(): " << t.elapsed() << std::endl;
+ }
+
+ return 0;
+}
+

0 comments on commit a8af35d

Please sign in to comment.
Something went wrong with that request. Please try again.