Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
cfb2f34e
Unverified
Commit
cfb2f34e
authored
May 01, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
fix benchmarks
parent
d0ef591c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
50 deletions
+51
-50
CMakeLists.txt
benchmarks/CMakeLists.txt
+4
-7
benchmarks.cpp
benchmarks/src/benchmarks.cpp
+33
-32
download_test_data.cmake
cmake/download_test_data.cmake
+11
-0
CMakeLists.txt
test/CMakeLists.txt
+3
-10
test_data.hpp.in
test/src/test_data.hpp.in
+0
-1
No files found.
benchmarks/CMakeLists.txt
View file @
cfb2f34e
...
@@ -14,15 +14,12 @@ add_subdirectory(thirdparty/benchmark)
...
@@ -14,15 +14,12 @@ add_subdirectory(thirdparty/benchmark)
include_directories
(
thirdparty
)
include_directories
(
thirdparty
)
include_directories
(
${
CMAKE_SOURCE_DIR
}
/../single_include
)
include_directories
(
${
CMAKE_SOURCE_DIR
}
/../single_include
)
# copy test files to build folder
# download test data
file
(
COPY
${
CMAKE_SOURCE_DIR
}
/data DESTINATION .
)
include
(
${
CMAKE_SOURCE_DIR
}
/../cmake/download_test_data.cmake
)
file
(
COPY
${
CMAKE_SOURCE_DIR
}
/../test/data/regression/floats.json
${
CMAKE_SOURCE_DIR
}
/../test/data/regression/unsigned_ints.json
${
CMAKE_SOURCE_DIR
}
/../test/data/regression/signed_ints.json
${
CMAKE_SOURCE_DIR
}
/../test/data/regression/small_signed_ints.json
DESTINATION data/numbers
)
# benchmark binary
# benchmark binary
add_executable
(
json_benchmarks src/benchmarks.cpp
)
add_executable
(
json_benchmarks src/benchmarks.cpp
)
target_compile_features
(
json_benchmarks PRIVATE cxx_std_11
)
target_compile_features
(
json_benchmarks PRIVATE cxx_std_11
)
target_link_libraries
(
json_benchmarks benchmark
${
CMAKE_THREAD_LIBS_INIT
}
)
target_link_libraries
(
json_benchmarks benchmark
${
CMAKE_THREAD_LIBS_INIT
}
)
add_dependencies
(
json_benchmarks download_test_data
)
target_include_directories
(
json_benchmarks PRIVATE
${
CMAKE_BINARY_DIR
}
/include
)
benchmarks/src/benchmarks.cpp
View file @
cfb2f34e
#include "benchmark/benchmark.h"
#include "benchmark/benchmark.h"
#include <nlohmann/json.hpp>
#include <nlohmann/json.hpp>
#include <fstream>
#include <fstream>
#include <test_data.hpp>
using
json
=
nlohmann
::
json
;
using
json
=
nlohmann
::
json
;
...
@@ -28,14 +29,14 @@ static void ParseFile(benchmark::State& state, const char* filename)
...
@@ -28,14 +29,14 @@ static void ParseFile(benchmark::State& state, const char* filename)
std
::
ifstream
file
(
filename
,
std
::
ios
::
binary
|
std
::
ios
::
ate
);
std
::
ifstream
file
(
filename
,
std
::
ios
::
binary
|
std
::
ios
::
ate
);
state
.
SetBytesProcessed
(
state
.
iterations
()
*
file
.
tellg
());
state
.
SetBytesProcessed
(
state
.
iterations
()
*
file
.
tellg
());
}
}
BENCHMARK_CAPTURE
(
ParseFile
,
jeopardy
,
"data
/jeopardy/jeopardy.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
jeopardy
,
TEST_DATA_DIRECTORY
"
/jeopardy/jeopardy.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
canada
,
"data
/nativejson-benchmark/canada.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
canada
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/canada.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
citm_catalog
,
"data
/nativejson-benchmark/citm_catalog.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
citm_catalog
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/citm_catalog.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
twitter
,
"data
/nativejson-benchmark/twitter.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
twitter
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/twitter.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
floats
,
"data/numbers
/floats.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
floats
,
TEST_DATA_DIRECTORY
"/regression
/floats.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
signed_ints
,
"data/numbers
/signed_ints.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
signed_ints
,
TEST_DATA_DIRECTORY
"/regression
/signed_ints.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
unsigned_ints
,
"data/numbers
/unsigned_ints.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
unsigned_ints
,
TEST_DATA_DIRECTORY
"/regression
/unsigned_ints.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
small_signed_ints
,
"data/numbers
/small_signed_ints.json"
);
BENCHMARK_CAPTURE
(
ParseFile
,
small_signed_ints
,
TEST_DATA_DIRECTORY
"/regression
/small_signed_ints.json"
);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// parse JSON from string
// parse JSON from string
...
@@ -61,14 +62,14 @@ static void ParseString(benchmark::State& state, const char* filename)
...
@@ -61,14 +62,14 @@ static void ParseString(benchmark::State& state, const char* filename)
state
.
SetBytesProcessed
(
state
.
iterations
()
*
str
.
size
());
state
.
SetBytesProcessed
(
state
.
iterations
()
*
str
.
size
());
}
}
BENCHMARK_CAPTURE
(
ParseString
,
jeopardy
,
"data
/jeopardy/jeopardy.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
jeopardy
,
TEST_DATA_DIRECTORY
"
/jeopardy/jeopardy.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
canada
,
"data
/nativejson-benchmark/canada.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
canada
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/canada.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
citm_catalog
,
"data
/nativejson-benchmark/citm_catalog.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
citm_catalog
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/citm_catalog.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
twitter
,
"data
/nativejson-benchmark/twitter.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
twitter
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/twitter.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
floats
,
"data/numbers
/floats.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
floats
,
TEST_DATA_DIRECTORY
"/regression
/floats.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
signed_ints
,
"data/numbers
/signed_ints.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
signed_ints
,
TEST_DATA_DIRECTORY
"/regression
/signed_ints.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
unsigned_ints
,
"data/numbers
/unsigned_ints.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
unsigned_ints
,
TEST_DATA_DIRECTORY
"/regression
/unsigned_ints.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
small_signed_ints
,
"data/numbers
/small_signed_ints.json"
);
BENCHMARK_CAPTURE
(
ParseString
,
small_signed_ints
,
TEST_DATA_DIRECTORY
"/regression
/small_signed_ints.json"
);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
...
@@ -88,22 +89,22 @@ static void Dump(benchmark::State& state, const char* filename, int indent)
...
@@ -88,22 +89,22 @@ static void Dump(benchmark::State& state, const char* filename, int indent)
state
.
SetBytesProcessed
(
state
.
iterations
()
*
j
.
dump
(
indent
).
size
());
state
.
SetBytesProcessed
(
state
.
iterations
()
*
j
.
dump
(
indent
).
size
());
}
}
BENCHMARK_CAPTURE
(
Dump
,
jeopardy
/
-
,
"data
/jeopardy/jeopardy.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
jeopardy
/
-
,
TEST_DATA_DIRECTORY
"
/jeopardy/jeopardy.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
jeopardy
/
4
,
"data
/jeopardy/jeopardy.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
jeopardy
/
4
,
TEST_DATA_DIRECTORY
"
/jeopardy/jeopardy.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
canada
/
-
,
"data
/nativejson-benchmark/canada.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
canada
/
-
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/canada.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
canada
/
4
,
"data
/nativejson-benchmark/canada.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
canada
/
4
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/canada.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
citm_catalog
/
-
,
"data
/nativejson-benchmark/citm_catalog.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
citm_catalog
/
-
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/citm_catalog.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
citm_catalog
/
4
,
"data
/nativejson-benchmark/citm_catalog.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
citm_catalog
/
4
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/citm_catalog.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
twitter
/
-
,
"data
/nativejson-benchmark/twitter.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
twitter
/
-
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/twitter.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
twitter
/
4
,
"data
/nativejson-benchmark/twitter.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
twitter
/
4
,
TEST_DATA_DIRECTORY
"
/nativejson-benchmark/twitter.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
floats
/
-
,
"data/numbers/floats.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
floats
/
-
,
TEST_DATA_DIRECTORY
"/regression/floats.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
floats
/
4
,
"data/numbers/floats.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
floats
/
4
,
TEST_DATA_DIRECTORY
"/regression/floats.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
signed_ints
/
-
,
"data/numbers/signed_ints.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
signed_ints
/
-
,
TEST_DATA_DIRECTORY
"/regression/signed_ints.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
signed_ints
/
4
,
"data/numbers/signed_ints.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
signed_ints
/
4
,
TEST_DATA_DIRECTORY
"/regression/signed_ints.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
unsigned_ints
/
-
,
"data/numbers/unsigned_ints.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
unsigned_ints
/
-
,
TEST_DATA_DIRECTORY
"/regression/unsigned_ints.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
unsigned_ints
/
4
,
"data/numbers/unsigned_ints.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
unsigned_ints
/
4
,
TEST_DATA_DIRECTORY
"/regression/unsigned_ints.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
small_signed_ints
/
-
,
"data/numbers/small_signed_ints.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
small_signed_ints
/
-
,
TEST_DATA_DIRECTORY
"/regression/small_signed_ints.json"
,
-
1
);
BENCHMARK_CAPTURE
(
Dump
,
small_signed_ints
/
4
,
"data/numbers/small_signed_ints.json"
,
4
);
BENCHMARK_CAPTURE
(
Dump
,
small_signed_ints
/
4
,
TEST_DATA_DIRECTORY
"/regression/small_signed_ints.json"
,
4
);
BENCHMARK_MAIN
();
BENCHMARK_MAIN
();
cmake/download_test_data.cmake
0 → 100644
View file @
cfb2f34e
find_package
(
Git
)
# target to download test data
add_custom_target
(
download_test_data
COMMAND test -d json_test_data ||
${
GIT_EXECUTABLE
}
clone https://github.com/nlohmann/json_test_data.git --quiet --depth 1
COMMENT
"Downloading test data from https://github.com/nlohmann/json_test_data"
WORKING_DIRECTORY
${
CMAKE_BINARY_DIR
}
)
# create a header with the path to the downloaded test data
file
(
WRITE
${
CMAKE_CURRENT_BINARY_DIR
}
/include/test_data.hpp
"#define TEST_DATA_DIRECTORY
\"
${
CMAKE_BINARY_DIR
}
/json_test_data
\"
"
)
test/CMakeLists.txt
View file @
cfb2f34e
...
@@ -3,20 +3,13 @@ option(JSON_Valgrind "Execute test suite with Valgrind" OFF)
...
@@ -3,20 +3,13 @@ option(JSON_Valgrind "Execute test suite with Valgrind" OFF)
option
(
JSON_NoExceptions
"Build test suite without exceptions"
OFF
)
option
(
JSON_NoExceptions
"Build test suite without exceptions"
OFF
)
option
(
JSON_Coverage
"Build test suite with coverage information"
OFF
)
option
(
JSON_Coverage
"Build test suite with coverage information"
OFF
)
# target to download test data
# download test data
find_package
(
Git
)
include
(
${
CMAKE_SOURCE_DIR
}
/cmake/download_test_data.cmake
)
add_custom_target
(
download_test_data
COMMAND test -d json_test_data ||
${
GIT_EXECUTABLE
}
clone https://github.com/nlohmann/json_test_data.git --quiet --depth 1
COMMENT
"Downloading test data from https://github.com/nlohmann/json_test_data"
WORKING_DIRECTORY
${
CMAKE_BINARY_DIR
}
)
# test fixture to download test data
# test fixture to download test data
add_test
(
NAME
"download_test_data"
COMMAND
${
CMAKE_COMMAND
}
--build
${
CMAKE_BINARY_DIR
}
--target download_test_data
)
add_test
(
NAME
"download_test_data"
COMMAND
${
CMAKE_COMMAND
}
--build
${
CMAKE_BINARY_DIR
}
--target download_test_data
)
set_tests_properties
(
download_test_data PROPERTIES FIXTURES_SETUP TEST_DATA
)
set_tests_properties
(
download_test_data PROPERTIES FIXTURES_SETUP TEST_DATA
)
configure_file
(
src/test_data.hpp.in include/test_data.hpp
)
if
(
JSON_Sanitizer
)
if
(
JSON_Sanitizer
)
message
(
STATUS
"Building test suite with Clang sanitizer"
)
message
(
STATUS
"Building test suite with Clang sanitizer"
)
if
(
NOT MSVC
)
if
(
NOT MSVC
)
...
...
test/src/test_data.hpp.in
deleted
100644 → 0
View file @
d0ef591c
#define TEST_DATA_DIRECTORY "${CMAKE_BINARY_DIR}/json_test_data"
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