From 28f11ac4291ce03d8bddec9ee8590330dff5d9b9 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 3 Feb 2016 11:33:27 +0800 Subject: [PATCH] Fix schema performance stats --- doc/schema.md | 4 ++-- doc/schema.zh-cn.md | 4 ++-- test/perftest/schematest.cpp | 11 +++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/doc/schema.md b/doc/schema.md index a310c79..4e07e9f 100644 --- a/doc/schema.md +++ b/doc/schema.md @@ -221,7 +221,7 @@ On a Mac Book Pro (2.8 GHz Intel Core i7), the following results are collected. |Validator|Relative speed|Number of test runs per second| |---------|:------------:|:----------------------------:| -|RapidJSON|36521%|7220217| +|RapidJSON|155%|30682| |[`ajv`](https://github.com/epoberezkin/ajv)|100%|19770 (± 1.31%)| |[`is-my-json-valid`](https://github.com/mafintosh/is-my-json-valid)|70%|13835 (± 2.84%)| |[`jsen`](https://github.com/bugventure/jsen)|57.7%|11411 (± 1.27%)| @@ -234,4 +234,4 @@ On a Mac Book Pro (2.8 GHz Intel Core i7), the following results are collected. |tv4|0.5%|93 (± 0.94%)| |[`jayschema`](https://github.com/natesilva/jayschema)|0.1%|21 (± 1.14%)| -That is, RapidJSON is about ~365 times faster than the fastest JavaScript library (ajv). And ~344 thousand times faster than the slowest one. +That is, RapidJSON is about 1.5x faster than the fastest JavaScript library (ajv). And 1400x faster than the slowest one. diff --git a/doc/schema.zh-cn.md b/doc/schema.zh-cn.md index 190285c..dd0ec73 100644 --- a/doc/schema.zh-cn.md +++ b/doc/schema.zh-cn.md @@ -221,7 +221,7 @@ RapidJSON 实现了一个简单的 NFA 正则表达式引擎,并预设使用 |校验器|相对速度|每秒执行的测试数目| |---------|:------------:|:----------------------------:| -|RapidJSON|36521%|7220217| +|RapidJSON|155%|30682| |[`ajv`](https://github.com/epoberezkin/ajv)|100%|19770 (± 1.31%)| |[`is-my-json-valid`](https://github.com/mafintosh/is-my-json-valid)|70%|13835 (± 2.84%)| |[`jsen`](https://github.com/bugventure/jsen)|57.7%|11411 (± 1.27%)| @@ -234,4 +234,4 @@ RapidJSON 实现了一个简单的 NFA 正则表达式引擎,并预设使用 |tv4|0.5%|93 (± 0.94%)| |[`jayschema`](https://github.com/natesilva/jayschema)|0.1%|21 (± 1.14%)| -换言之,RapidJSON 比最快的 JavaScript 库(ajv)快约 365 倍。比最慢的快 34 万倍。 +换言之,RapidJSON 比最快的 JavaScript 库(ajv)快约 1.5x。比最慢的快 1400x。 diff --git a/test/perftest/schematest.cpp b/test/perftest/schematest.cpp index dc27e44..468f5fe 100644 --- a/test/perftest/schematest.cpp +++ b/test/perftest/schematest.cpp @@ -100,7 +100,8 @@ public: } for (Value::ConstValueIterator schemaItr = d.Begin(); schemaItr != d.End(); ++schemaItr) { - if (IsExcludeTestSuite((*schemaItr)["description"].GetString())) + std::string schemaDescription = (*schemaItr)["description"].GetString(); + if (IsExcludeTestSuite(schemaDescription)) continue; TestSuite* ts = new TestSuite; @@ -108,7 +109,7 @@ public: const Value& tests = (*schemaItr)["tests"]; for (Value::ConstValueIterator testItr = tests.Begin(); testItr != tests.End(); ++testItr) { - if (IsExcludeTest((*testItr)["description"].GetString())) + if (IsExcludeTest(schemaDescription + ", " + (*testItr)["description"].GetString())) continue; Document* d2 = new Document; @@ -191,9 +192,10 @@ TEST_F(Schema, TestSuite) { char validatorBuffer[65536]; MemoryPoolAllocator<> validatorAllocator(validatorBuffer, sizeof(validatorBuffer)); + const int trialCount = 100000; int testCount = 0; clock_t start = clock(); - for (int i = 0; i < 10000; i++) { + for (int i = 0; i < trialCount; i++) { for (TestSuiteList::const_iterator itr = testSuites.begin(); itr != testSuites.end(); ++itr) { const TestSuite& ts = **itr; GenericSchemaValidator >, MemoryPoolAllocator<> > validator(*ts.schema, &validatorAllocator); @@ -207,7 +209,8 @@ TEST_F(Schema, TestSuite) { } clock_t end = clock(); double duration = double(end - start) / CLOCKS_PER_SEC; - printf("%d tests in %f s -> %f tests per sec\n", testCount, duration, testCount / duration); + printf("%d trials in %f s -> %f trials per sec\n", trialCount, duration, trialCount / duration); + printf("%d tests per trial\n", testCount / trialCount); } #endif