Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
717a8a95
Commit
717a8a95
authored
Dec 21, 2012
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add performance tests from Karma.
parent
f925daa0
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
603 additions
and
0 deletions
+603
-0
tests/high_resolution_timer.hpp
tests/high_resolution_timer.hpp
+474
-0
tests/int_generator.cpp
tests/int_generator.cpp
+129
-0
No files found.
tests/high_resolution_timer.hpp
0 → 100644
View file @
717a8a95
This diff is collapsed.
Click to expand it.
tests/int_generator.cpp
0 → 100644
View file @
717a8a95
// Copyright (c) 2001-2010 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <climits>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <boost/format.hpp>
#include "../high_resolution_timer.hpp"
// This value specifies, how to unroll the integer string generation loop in
// Karma.
// Set this to some integer in between 0 (no unrolling) and max expected
// integer string len (complete unrolling). If not specified, this value
// defaults to 6.
#define BOOST_KARMA_NUMERICS_LOOP_UNROLL 6
#include <boost/spirit/include/karma.hpp>
using
namespace
std
;
using
namespace
boost
::
spirit
;
#define MAX_ITERATION 10000000
///////////////////////////////////////////////////////////////////////////////
struct
random_fill
{
int
operator
()()
const
{
int
scale
=
std
::
rand
()
/
100
+
1
;
return
(
std
::
rand
()
*
std
::
rand
())
/
scale
;
}
};
///////////////////////////////////////////////////////////////////////////////
int
main
()
{
namespace
karma
=
boost
::
spirit
::
karma
;
cout
<<
"Converting "
<<
MAX_ITERATION
<<
" randomly generated int values to strings."
<<
flush
<<
endl
;
std
::
srand
(
0
);
std
::
vector
<
int
>
v
(
MAX_ITERATION
);
std
::
generate
(
v
.
begin
(),
v
.
end
(),
random_fill
());
// randomly fill the vector
// test the C libraries ltoa function (the most low level function for
// string conversion available)
{
//[karma_int_performance_ltoa
char
buffer
[
65
];
// we don't expect more than 64 bytes to be generated here
//<-
std
::
string
str
;
util
::
high_resolution_timer
t
;
//->
for
(
int
i
=
0
;
i
<
MAX_ITERATION
;
++
i
)
{
ltoa
(
v
[
i
],
buffer
,
10
);
//<-
str
=
buffer
;
// compensate for string ops in other benchmarks
//->
}
//]
cout
<<
"ltoa:
\t\t
"
<<
t
.
elapsed
()
<<
" [s]"
<<
flush
<<
endl
;
}
// test the iostreams library
{
//[karma_int_performance_iostreams
std
::
stringstream
str
;
//<-
util
::
high_resolution_timer
t
;
//->
for
(
int
i
=
0
;
i
<
MAX_ITERATION
;
++
i
)
{
str
.
str
(
""
);
str
<<
v
[
i
];
}
//]
cout
<<
"iostreams:
\t
"
<<
t
.
elapsed
()
<<
" [s]"
<<
flush
<<
endl
;
}
// test the Boost.Format library
{
//[karma_int_performance_format
std
::
string
str
;
boost
::
format
int_format
(
"%d"
);
//<-
util
::
high_resolution_timer
t
;
//->
for
(
int
i
=
0
;
i
<
MAX_ITERATION
;
++
i
)
{
str
=
boost
::
str
(
int_format
%
v
[
i
]);
}
//]
cout
<<
"Boost.Format:
\t
"
<<
t
.
elapsed
()
<<
" [s]"
<<
flush
<<
endl
;
}
// test the Karma int_ generation routines
{
std
::
string
str
;
util
::
high_resolution_timer
t
;
//[karma_int_performance_plain
char
buffer
[
65
];
// we don't expect more than 64 bytes to be generated here
for
(
int
i
=
0
;
i
<
MAX_ITERATION
;
++
i
)
{
char
*
ptr
=
buffer
;
karma
::
generate
(
ptr
,
int_
,
v
[
i
]);
*
ptr
=
'\0'
;
//<-
str
=
buffer
;
// compensate for string ops in other benchmarks
//->
}
//]
cout
<<
"int_:
\t\t
"
<<
t
.
elapsed
()
<<
" [s]"
<<
flush
<<
endl
;
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment