Skip to content

Commit 1a5d8f1

Browse files
committed
Add tests for SIMDJSON_EXCEPTIONS=0, add tie() support
1 parent 03c828c commit 1a5d8f1

24 files changed

+992
-764
lines changed

.drone.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,28 @@ steps:
178178
- make -j
179179
- ctest --output-on-failure
180180
---
181+
kind: pipeline
182+
name: amd64_clang_cmake_no_exceptions
183+
184+
platform:
185+
os: linux
186+
arch: amd64
187+
188+
steps:
189+
- name: Build and Test
190+
image: ubuntu:18.04
191+
environment:
192+
CC: clang
193+
CXX: clang++
194+
CMAKE_FLAGS: -DSIMDJSON_BUILD_STATIC=OFF
195+
commands:
196+
- apt-get update -qq
197+
- apt-get install -y clang make cmake
198+
- $CC --version
199+
- mkdir build && cd build
200+
- cmake $CMAKE_FLAGS ..
201+
- make -j
202+
- ctest --output-on-failure
181203
kind: pipeline
182204
name: amd64_clang_cmake_static
183205

benchmark/bench_dom_api.cpp

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ using namespace std;
1212

1313
const padded_string EMPTY_ARRAY("[]", 2);
1414

15+
#if SIMDJSON_EXCEPTIONS
16+
1517
static void twitter_count(State& state) {
1618
// Prints the number of results in twitter.json
1719
document doc = document::load(JSON_TEST_PATH);
@@ -22,17 +24,6 @@ static void twitter_count(State& state) {
2224
}
2325
BENCHMARK(twitter_count);
2426

25-
static void error_code_twitter_count(State& state) noexcept {
26-
// Prints the number of results in twitter.json
27-
document doc = document::load(JSON_TEST_PATH);
28-
for (auto _ : state) {
29-
auto [value, error] = doc["search_metadata"]["count"];
30-
if (error) { return; }
31-
if (uint64_t(value) != 100) { return; }
32-
}
33-
}
34-
BENCHMARK(error_code_twitter_count);
35-
3627
static void iterator_twitter_count(State& state) {
3728
// Prints the number of results in twitter.json
3829
document doc = document::load(JSON_TEST_PATH);
@@ -65,6 +56,39 @@ static void twitter_default_profile(State& state) {
6556
}
6657
BENCHMARK(twitter_default_profile);
6758

59+
static void twitter_image_sizes(State& state) {
60+
// Count unique image sizes
61+
document doc = document::load(JSON_TEST_PATH);
62+
for (auto _ : state) {
63+
set<tuple<uint64_t, uint64_t>> image_sizes;
64+
for (document::object tweet : doc["statuses"].as_array()) {
65+
auto [media, not_found] = tweet["entities"]["media"];
66+
if (!not_found) {
67+
for (document::object image : media.as_array()) {
68+
for (auto [key, size] : image["sizes"].as_object()) {
69+
image_sizes.insert({ size["w"], size["h"] });
70+
}
71+
}
72+
}
73+
}
74+
if (image_sizes.size() != 15) { return; };
75+
}
76+
}
77+
BENCHMARK(twitter_image_sizes);
78+
79+
#endif // SIMDJSON_EXCEPTIONS
80+
81+
static void error_code_twitter_count(State& state) noexcept {
82+
// Prints the number of results in twitter.json
83+
document doc = document::load(JSON_TEST_PATH);
84+
for (auto _ : state) {
85+
auto [value, error] = doc["search_metadata"]["count"].as_uint64_t();
86+
if (error) { return; }
87+
if (value != 100) { return; }
88+
}
89+
}
90+
BENCHMARK(error_code_twitter_count);
91+
6892
static void error_code_twitter_default_profile(State& state) noexcept {
6993
// Count unique users with a default profile.
7094
document doc = document::load(JSON_TEST_PATH);
@@ -127,26 +151,6 @@ static void iterator_twitter_default_profile(State& state) {
127151
}
128152
BENCHMARK(iterator_twitter_default_profile);
129153

130-
static void twitter_image_sizes(State& state) {
131-
// Count unique image sizes
132-
document doc = document::load(JSON_TEST_PATH);
133-
for (auto _ : state) {
134-
set<tuple<uint64_t, uint64_t>> image_sizes;
135-
for (document::object tweet : doc["statuses"].as_array()) {
136-
auto [media, not_found] = tweet["entities"]["media"];
137-
if (!not_found) {
138-
for (document::object image : media.as_array()) {
139-
for (auto [key, size] : image["sizes"].as_object()) {
140-
image_sizes.insert({ size["w"], size["h"] });
141-
}
142-
}
143-
}
144-
}
145-
if (image_sizes.size() != 15) { return; };
146-
}
147-
}
148-
BENCHMARK(twitter_image_sizes);
149-
150154
static void error_code_twitter_image_sizes(State& state) noexcept {
151155
// Count unique image sizes
152156
document doc = document::load(JSON_TEST_PATH);

benchmark/benchmarker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ struct benchmarker {
304304
// Run it once to get hot buffers
305305
if(hotbuffers) {
306306
auto result = parser.parse((const uint8_t *)json.data(), json.size());
307-
if (result.error) {
308-
exit_error(string("Failed to parse ") + filename + string(":") + error_message(result.error));
307+
if (result.error()) {
308+
exit_error(string("Failed to parse ") + filename + string(":") + error_message(result.error()));
309309
}
310310
}
311311

benchmark/distinctuseridcompetition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ simdjson_compute_stats(const simdjson::padded_string &p) {
6767

6868
__attribute__((noinline)) bool
6969
simdjson_just_parse(const simdjson::padded_string &p) {
70-
return simdjson::document::parse(p).error != simdjson::SUCCESS;
70+
return simdjson::document::parse(p).error() != simdjson::SUCCESS;
7171
}
7272

7373
void sajson_traverse(std::vector<int64_t> &answer, const sajson::value &node) {

benchmark/parse_stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int main (int argc, char *argv[]){
8282
auto start = std::chrono::steady_clock::now();
8383
count = 0;
8484
for (auto result : parser.parse_many(p, 4000000)) {
85-
error = result.error;
85+
error = result.error();
8686
count++;
8787
}
8888
auto end = std::chrono::steady_clock::now();
@@ -121,7 +121,7 @@ int main (int argc, char *argv[]){
121121
auto start = std::chrono::steady_clock::now();
122122
// TODO this includes allocation of the parser; is that intentional?
123123
for (auto result : parser.parse_many(p, 4000000)) {
124-
error = result.error;
124+
error = result.error();
125125
}
126126
auto end = std::chrono::steady_clock::now();
127127

fuzz/fuzz_dump.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
4747

4848
try {
4949
auto pj = simdjson::build_parsed_json(Data, Size);
50-
simdjson::ParsedJson::Iterator pjh(pj);
50+
if (!pj.is_valid()) {
51+
throw 1;
52+
}
53+
simdjson::ParsedJson::Iterator pjh(pj.doc);
5154
if (pjh.is_ok()) {
5255
compute_dump(pjh);
5356
}

0 commit comments

Comments
 (0)