|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55053 - trunk/libs/spirit/benchmarks/qi
From: joel_at_[hidden]
Date: 2009-07-21 03:09:44
Author: djowel
Date: 2009-07-21 03:09:43 EDT (Tue, 21 Jul 2009)
New Revision: 55053
URL: http://svn.boost.org/trac/boost/changeset/55053
Log:
benchmark updates
Text files modified:
trunk/libs/spirit/benchmarks/qi/uint_parser.cpp | 107 +++++++++++++++++++++++++++++++++++++--
1 files changed, 100 insertions(+), 7 deletions(-)
Modified: trunk/libs/spirit/benchmarks/qi/uint_parser.cpp
==============================================================================
--- trunk/libs/spirit/benchmarks/qi/uint_parser.cpp (original)
+++ trunk/libs/spirit/benchmarks/qi/uint_parser.cpp 2009-07-21 03:09:43 EDT (Tue, 21 Jul 2009)
@@ -17,14 +17,15 @@
#include <cstdlib>
#include <string>
#include <vector>
+#include <sstream>
-#define MAX_ITERATION 10000000
+#define MAX_ITERATION 1000000
void check(int a, int b)
{
if (a != b)
{
- std::cout << "Parse Error" << std::endl;
+ std::cout << "Parse Error, got: " << a << " and " << b << std::endl;
abort();
}
}
@@ -40,19 +41,28 @@
for (int i = 0; i < MAX_ITERATION; ++i)
{
src[i] = std::rand() * std::rand();
+ if (std::rand() % 2)
+ src[i] = -src[i];
src_str[i] = boost::lexical_cast<std::string>(src[i]);
}
- std::vector<int> v(MAX_ITERATION);
-
// test the C libraries atoi function (the most low level function for
// string conversion available)
{
+ std::vector<int> v(MAX_ITERATION);
+ std::vector<char const*> f(MAX_ITERATION);
+
+ // get the C string
+ for (int i = 0; i < MAX_ITERATION; ++i)
+ {
+ f[i] = src_str[i].c_str();
+ }
+
util::high_resolution_timer t;
for (int i = 0; i < MAX_ITERATION; ++i)
{
- v[i] = atoi(src_str[i].c_str());
+ v[i] = atoi(f[i]);
}
std::cout << "atoi: " << t.elapsed() << " [s]" << std::flush << std::endl;
@@ -66,11 +76,20 @@
// test the C libraries strtol function (the most low level function for
// string conversion available)
{
+ std::vector<int> v(MAX_ITERATION);
+ std::vector<char const*> f(MAX_ITERATION);
+
+ // get the C string
+ for (int i = 0; i < MAX_ITERATION; ++i)
+ {
+ f[i] = src_str[i].c_str();
+ }
+
util::high_resolution_timer t;
for (int i = 0; i < MAX_ITERATION; ++i)
{
- v[i] = strtol(src_str[i].c_str(), 0, 10);
+ v[i] = strtol(f[i], 0, 10);
}
std::cout << "strtol: " << t.elapsed() << " [s]" << std::flush << std::endl;
@@ -81,8 +100,82 @@
}
}
+ // test sscanf
+ {
+ std::vector<int> v(MAX_ITERATION);
+ std::vector<char const*> f(MAX_ITERATION);
+
+ // get the C string
+ for (int i = 0; i < MAX_ITERATION; ++i)
+ {
+ f[i] = src_str[i].c_str();
+ }
+
+ util::high_resolution_timer t;
+
+ for (int i = 0; i < MAX_ITERATION; ++i)
+ {
+ sscanf(f[i], "%d", &v[i]);
+ }
+
+ std::cout << "sscanf: " << t.elapsed() << " [s]" << std::flush << std::endl;
+
+ for (int i = 0; i < MAX_ITERATION; ++i)
+ {
+ check(v[i], src[i]);
+ }
+ }
+
+ // test iostream
+ {
+ std::istringstream ss;
+ std::vector<int> v(MAX_ITERATION);
+ util::high_resolution_timer t;
+
+ for (int i = 0; i < MAX_ITERATION; ++i)
+ {
+ ss.clear();
+ ss.str(src_str[i]);
+ ss >> v[i];
+ }
+
+ std::cout << "std::iostream: " << t.elapsed() << " [s]" << std::flush << std::endl;
+
+ for (int i = 0; i < MAX_ITERATION; ++i)
+ {
+ check(v[i], src[i]);
+ }
+ }
+
+ // test boost::lexical_cast
+ {
+ std::vector<int> v(MAX_ITERATION);
+ std::vector<char const*> f(MAX_ITERATION);
+
+ // get the C string
+ for (int i = 0; i < MAX_ITERATION; ++i)
+ {
+ f[i] = src_str[i].c_str();
+ }
+
+ util::high_resolution_timer t;
+
+ for (int i = 0; i < MAX_ITERATION; ++i)
+ {
+ v[i] = boost::lexical_cast<int>(src[i]);
+ }
+
+ std::cout << "boost::lexical_cast: " << t.elapsed() << " [s]" << std::flush << std::endl;
+
+ for (int i = 0; i < MAX_ITERATION; ++i)
+ {
+ check(v[i], src[i]);
+ }
+ }
+
// test the Qi int_ parser routines
{
+ std::vector<int> v(MAX_ITERATION);
std::vector<char const*> f(MAX_ITERATION);
std::vector<char const*> l(MAX_ITERATION);
@@ -102,7 +195,7 @@
qi::parse(f[i], l[i], int_, v[i]);
}
- std::cout << "int_: " << t.elapsed() << " [s]" << std::flush << std::endl;
+ std::cout << "spirit int_: " << t.elapsed() << " [s]" << std::flush << std::endl;
for (int i = 0; i < MAX_ITERATION; ++i)
{
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk