OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/perf/perf_test.h" | 11 #include "testing/perf/perf_test.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 namespace { | 15 namespace { |
16 // Generates a simple dictionary value with simple data types, a string and a | 16 // Generates a simple dictionary value with simple data types, a string and a |
17 // list. | 17 // list. |
18 std::unique_ptr<DictionaryValue> GenerateDict() { | 18 std::unique_ptr<DictionaryValue> GenerateDict() { |
19 auto root = MakeUnique<DictionaryValue>(); | 19 auto root = MakeUnique<DictionaryValue>(); |
20 root->SetDouble("Double", 3.141); | 20 root->SetDouble("Double", 3.141); |
21 root->SetBoolean("Bool", true); | 21 root->SetBoolean("Bool", true); |
22 root->SetInteger("Int", 42); | 22 root->SetInteger("Int", 42); |
23 root->SetString("String", "Foo"); | 23 root->SetString("String", "Foo"); |
24 | 24 |
25 auto list = MakeUnique<ListValue>(); | 25 auto list = MakeUnique<ListValue>(); |
26 list->Set(0, MakeUnique<FundamentalValue>(2.718)); | 26 list->Set(0, MakeUnique<Value>(2.718)); |
27 list->Set(1, MakeUnique<FundamentalValue>(false)); | 27 list->Set(1, MakeUnique<Value>(false)); |
28 list->Set(2, MakeUnique<FundamentalValue>(123)); | 28 list->Set(2, MakeUnique<Value>(123)); |
29 list->Set(3, MakeUnique<StringValue>("Bar")); | 29 list->Set(3, MakeUnique<StringValue>("Bar")); |
30 root->Set("List", std::move(list)); | 30 root->Set("List", std::move(list)); |
31 | 31 |
32 return root; | 32 return root; |
33 } | 33 } |
34 | 34 |
35 // Generates a tree-like dictionary value with a size of O(breadth ** depth). | 35 // Generates a tree-like dictionary value with a size of O(breadth ** depth). |
36 std::unique_ptr<DictionaryValue> GenerateLayeredDict(int breadth, int depth) { | 36 std::unique_ptr<DictionaryValue> GenerateLayeredDict(int breadth, int depth) { |
37 if (depth == 1) | 37 if (depth == 1) |
38 return GenerateDict(); | 38 return GenerateDict(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 TEST_F(JSONPerfTest, StressTest) { | 76 TEST_F(JSONPerfTest, StressTest) { |
77 for (int i = 0; i < 4; ++i) { | 77 for (int i = 0; i < 4; ++i) { |
78 for (int j = 0; j < 12; ++j) { | 78 for (int j = 0; j < 12; ++j) { |
79 TestWriteAndRead(i + 1, j + 1); | 79 TestWriteAndRead(i + 1, j + 1); |
80 } | 80 } |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 } // namespace base | 84 } // namespace base |
OLD | NEW |