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
75343c7e
Commit
75343c7e
authored
Dec 21, 2012
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add format to int_generator tests.
parent
717a8a95
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
10 deletions
+41
-10
CMakeLists.txt
CMakeLists.txt
+10
-4
format.h
format.h
+4
-0
tests/int_generator.cpp
tests/int_generator.cpp
+27
-6
No files found.
CMakeLists.txt
View file @
75343c7e
...
@@ -40,12 +40,18 @@ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt)
...
@@ -40,12 +40,18 @@ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt)
add_test
(
format_test format_test
)
add_test
(
format_test format_test
)
endif
()
endif
()
if
(
EXISTS
${
CMAKE_CURRENT_SOURCE_DIR
}
/tinyformat/tinyformat_test.cpp
)
find_package
(
Boost
)
find_package
(
Boost
)
if
(
Boost_FOUND
)
if
(
Boost_FOUND
)
add_executable
(
int_generator tests/int_generator.cpp
)
add_definitions
(
-DHAVE_BOOST
)
target_link_libraries
(
int_generator format
)
find_library
(
HAVE_RT rt
)
if
(
HAVE_RT
)
target_link_libraries
(
int_generator rt
)
endif
()
endif
()
add_definitions
(
-DHAVE_BOOST
)
endif
()
if
(
EXISTS
${
CMAKE_CURRENT_SOURCE_DIR
}
/tinyformat/tinyformat_test.cpp
)
add_executable
(
tinyformat_speed_test tinyformat/tinyformat_test.cpp
)
add_executable
(
tinyformat_speed_test tinyformat/tinyformat_test.cpp
)
target_link_libraries
(
tinyformat_speed_test format
)
target_link_libraries
(
tinyformat_speed_test format
)
set_target_properties
(
tinyformat_speed_test PROPERTIES COMPILE_DEFINITIONS
set_target_properties
(
tinyformat_speed_test PROPERTIES COMPILE_DEFINITIONS
...
...
format.h
View file @
75343c7e
...
@@ -306,6 +306,10 @@ class Formatter {
...
@@ -306,6 +306,10 @@ class Formatter {
// using inserter operator<<.
// using inserter operator<<.
internal
::
ArgInserter
operator
()(
const
char
*
format
);
internal
::
ArgInserter
operator
()(
const
char
*
format
);
void
operator
<<
(
int
value
)
{
FormatInt
(
value
,
FormatSpec
());
}
std
::
size_t
size
()
const
{
return
buffer_
.
size
();
}
std
::
size_t
size
()
const
{
return
buffer_
.
size
();
}
const
char
*
data
()
const
{
return
&
buffer_
[
0
];
}
const
char
*
data
()
const
{
return
&
buffer_
[
0
];
}
...
...
tests/int_generator.cpp
View file @
75343c7e
...
@@ -10,7 +10,9 @@
...
@@ -10,7 +10,9 @@
#include <sstream>
#include <sstream>
#include <boost/format.hpp>
#include <boost/format.hpp>
#include "../high_resolution_timer.hpp"
#include "high_resolution_timer.hpp"
#include "../format.h"
// This value specifies, how to unroll the integer string generation loop in
// This value specifies, how to unroll the integer string generation loop in
// Karma.
// Karma.
...
@@ -48,10 +50,10 @@ int main()
...
@@ -48,10 +50,10 @@ int main()
std
::
vector
<
int
>
v
(
MAX_ITERATION
);
std
::
vector
<
int
>
v
(
MAX_ITERATION
);
std
::
generate
(
v
.
begin
(),
v
.
end
(),
random_fill
());
// randomly fill the vector
std
::
generate
(
v
.
begin
(),
v
.
end
(),
random_fill
());
// randomly fill the vector
// test the C libraries
ltoa
function (the most low level function for
// test the C libraries
sprintf
function (the most low level function for
// string conversion available)
// string conversion available)
{
{
//[karma_int_performance_
ltoa
//[karma_int_performance_
sprintf
char
buffer
[
65
];
// we don't expect more than 64 bytes to be generated here
char
buffer
[
65
];
// we don't expect more than 64 bytes to be generated here
//<-
//<-
std
::
string
str
;
std
::
string
str
;
...
@@ -59,14 +61,14 @@ int main()
...
@@ -59,14 +61,14 @@ int main()
//->
//->
for
(
int
i
=
0
;
i
<
MAX_ITERATION
;
++
i
)
for
(
int
i
=
0
;
i
<
MAX_ITERATION
;
++
i
)
{
{
ltoa
(
v
[
i
],
buffer
,
10
);
sprintf
(
buffer
,
"%d"
,
v
[
i
]
);
//<-
//<-
str
=
buffer
;
// compensate for string ops in other benchmarks
str
=
buffer
;
// compensate for string ops in other benchmarks
//->
//->
}
}
//]
//]
cout
<<
"
ltoa
:
\t\t
"
<<
t
.
elapsed
()
<<
" [s]"
<<
flush
<<
endl
;
cout
<<
"
sprintf
:
\t\t
"
<<
t
.
elapsed
()
<<
" [s]"
<<
flush
<<
endl
;
}
}
// test the iostreams library
// test the iostreams library
...
@@ -88,7 +90,7 @@ int main()
...
@@ -88,7 +90,7 @@ int main()
// test the Boost.Format library
// test the Boost.Format library
{
{
//[karma_int_performance_
forma
t
//[karma_int_performance_
boos
t
std
::
string
str
;
std
::
string
str
;
boost
::
format
int_format
(
"%d"
);
boost
::
format
int_format
(
"%d"
);
//<-
//<-
...
@@ -124,6 +126,25 @@ int main()
...
@@ -124,6 +126,25 @@ int main()
cout
<<
"int_:
\t\t
"
<<
t
.
elapsed
()
<<
" [s]"
<<
flush
<<
endl
;
cout
<<
"int_:
\t\t
"
<<
t
.
elapsed
()
<<
" [s]"
<<
flush
<<
endl
;
}
}
// test the format library
{
std
::
string
str
;
util
::
high_resolution_timer
t
;
//[karma_int_performance_format
for
(
int
i
=
0
;
i
<
MAX_ITERATION
;
++
i
)
{
fmt
::
Formatter
format
;
format
<<
v
[
i
];
//<-
str
=
format
.
c_str
();
// compensate for string ops in other benchmarks
//->
}
//]
cout
<<
"format:
\t\t
"
<<
t
.
elapsed
()
<<
" [s]"
<<
flush
<<
endl
;
}
return
0
;
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