18 #define TEST_RAPIDJSON 1 19 #define TEST_PLATFORM 0 22 #define TEST_VERSION_CODE(x,y,z) \ 23 (((x)*100000) + ((y)*100) + (z)) 28 #if defined(__SSE4_2__) 29 # define RAPIDJSON_SSE42 30 #elif defined(__SSE2__) 31 # define RAPIDJSON_SSE2 32 #elif defined(__ARM_NEON) 33 # define RAPIDJSON_NEON 36 #define RAPIDJSON_HAS_STDSTRING 1 44 #ifndef __STDC_CONSTANT_MACROS 45 # define __STDC_CONSTANT_MACROS 1 // required by C++ standard 48 #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) 49 #if defined(__clang__) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) 50 #pragma GCC diagnostic push 52 #pragma GCC diagnostic ignored "-Weffc++" 55 #include "gtest/gtest.h" 57 #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) 58 #pragma GCC diagnostic pop 62 #define _CRTDBG_MAP_ALLOC 64 #pragma warning(disable : 4996) // 'function': was declared deprecated 68 class PerfTest :
public ::testing::Test {
70 PerfTest() : filename_(), json_(), length_(), whitespace_(), whitespace_length_() {}
72 virtual void SetUp() {
74 const char *paths[] = {
76 "bin/data/sample.json",
77 "../bin/data/sample.json",
78 "../../bin/data/sample.json",
79 "../../../bin/data/sample.json" 83 for (
size_t i = 0; i <
sizeof(paths) /
sizeof(paths[0]); i++) {
84 fp = fopen(filename_ = paths[i],
"rb");
90 fseek(fp, 0, SEEK_END);
91 length_ = (size_t)ftell(fp);
92 fseek(fp, 0, SEEK_SET);
93 json_ = (
char*)malloc(length_ + 1);
94 ASSERT_EQ(length_, fread(json_, 1, length_, fp));
95 json_[length_] =
'\0';
101 whitespace_length_ = 1024 * 1024;
102 whitespace_ = (
char *)malloc(whitespace_length_ + 4);
103 char *p = whitespace_;
104 for (
size_t i = 0; i < whitespace_length_; i += 4) {
118 const char *typespaths[] = {
126 const char* typesfilenames[] = {
136 for (
size_t j = 0; j <
sizeof(typesfilenames) /
sizeof(typesfilenames[0]); j++) {
138 for (
size_t i = 0; i <
sizeof(typespaths) /
sizeof(typespaths[0]); i++) {
140 sprintf(filename,
"%s/%s", typespaths[i], typesfilenames[j]);
141 if (FILE* fp = fopen(filename,
"rb")) {
142 fseek(fp, 0, SEEK_END);
143 typesLength_[j] = (size_t)ftell(fp);
144 fseek(fp, 0, SEEK_SET);
145 types_[j] = (
char*)malloc(typesLength_[j] + 1);
146 ASSERT_EQ(typesLength_[j], fread(types_[j], 1, typesLength_[j], fp));
147 types_[j][typesLength_[j]] =
'\0';
156 virtual void TearDown() {
161 for (
size_t i = 0; i < 7; i++) {
168 PerfTest(
const PerfTest&);
169 PerfTest& operator=(
const PerfTest&);
172 const char* filename_;
176 size_t whitespace_length_;
178 size_t typesLength_[7];
180 static const size_t kTrialCount = 1000;
183 #endif // __cplusplus 185 #endif // PERFTEST_H_