summaryrefslogtreecommitdiff
path: root/utils/json-bench
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2011-12-19 09:32:05 +0000
committerManuel Klimek <klimek@google.com>2011-12-19 09:32:05 +0000
commitd21428a5eba17d77c2df4af69ad6006f466ed1a5 (patch)
treeb663f1f3c396166068294a9aa0f2b0c30c996648 /utils/json-bench
parent53ce4286469b7a565674dc253d9e69b3cfeb7054 (diff)
downloadllvm-d21428a5eba17d77c2df4af69ad6006f466ed1a5.tar.gz
llvm-d21428a5eba17d77c2df4af69ad6006f466ed1a5.tar.bz2
llvm-d21428a5eba17d77c2df4af69ad6006f466ed1a5.tar.xz
Adds a flag to allow specifying the memory limitations of the JSON benchmark.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146863 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/json-bench')
-rw-r--r--utils/json-bench/JSONBench.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/utils/json-bench/JSONBench.cpp b/utils/json-bench/JSONBench.cpp
index b9f4af63d0..810ebfcdef 100644
--- a/utils/json-bench/JSONBench.cpp
+++ b/utils/json-bench/JSONBench.cpp
@@ -23,6 +23,11 @@ Verify("verify", llvm::cl::desc(
"Run a quick verification useful for regression testing"),
llvm::cl::init(false));
+static llvm::cl::opt<unsigned>
+MemoryLimitMB("memory-limit", llvm::cl::desc(
+ "Do not use more megabytes of memory"),
+ llvm::cl::init(1000));
+
void benchmark(llvm::TimerGroup &Group, llvm::StringRef Name,
llvm::StringRef JSONText) {
llvm::Timer BaseLine((Name + ": Loop").str(), Group);
@@ -44,17 +49,19 @@ void benchmark(llvm::TimerGroup &Group, llvm::StringRef Name,
Parsing.stopTimer();
}
-std::string createJSONText(int N, int ValueSize) {
+std::string createJSONText(unsigned MemoryMB, unsigned ValueSize) {
std::string JSONText;
llvm::raw_string_ostream Stream(JSONText);
Stream << "[\n";
- for (int I = 0; I < N; ++I) {
+ unsigned MemoryBytes = MemoryMB * 1024 * 1024;
+ while (JSONText.size() < MemoryBytes) {
Stream << " {\n"
<< " \"key1\": \"" << std::string(ValueSize, '*') << "\",\n"
<< " \"key2\": \"" << std::string(ValueSize, '*') << "\",\n"
<< " \"key3\": \"" << std::string(ValueSize, '*') << "\"\n"
<< " }";
- if (I + 1 < N) Stream << ",";
+ Stream.flush();
+ if (JSONText.size() < MemoryBytes) Stream << ",";
Stream << "\n";
}
Stream << "]\n";
@@ -66,11 +73,11 @@ int main(int argc, char **argv) {
llvm::cl::ParseCommandLineOptions(argc, argv);
llvm::TimerGroup Group("JSON parser benchmark");
if (Verify) {
- benchmark(Group, "Fast", createJSONText(1000, 500));
+ benchmark(Group, "Fast", createJSONText(10, 500));
} else {
- benchmark(Group, "Small Values", createJSONText(1000000, 5));
- benchmark(Group, "Medium Values", createJSONText(1000000, 500));
- benchmark(Group, "Large Values", createJSONText(10000, 50000));
+ benchmark(Group, "Small Values", createJSONText(MemoryLimitMB, 5));
+ benchmark(Group, "Medium Values", createJSONText(MemoryLimitMB, 500));
+ benchmark(Group, "Large Values", createJSONText(MemoryLimitMB, 50000));
}
return 0;
}