[llvm-commits] [llvm] r146863 - /llvm/trunk/utils/json-bench/JSONBench.cpp
Manuel Klimek
klimek at google.com
Mon Dec 19 01:32:05 PST 2011
Author: klimek
Date: Mon Dec 19 03:32:05 2011
New Revision: 146863
URL: http://llvm.org/viewvc/llvm-project?rev=146863&view=rev
Log:
Adds a flag to allow specifying the memory limitations of the JSON benchmark.
Modified:
llvm/trunk/utils/json-bench/JSONBench.cpp
Modified: llvm/trunk/utils/json-bench/JSONBench.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/json-bench/JSONBench.cpp?rev=146863&r1=146862&r2=146863&view=diff
==============================================================================
--- llvm/trunk/utils/json-bench/JSONBench.cpp (original)
+++ llvm/trunk/utils/json-bench/JSONBench.cpp Mon Dec 19 03:32:05 2011
@@ -23,6 +23,11 @@
"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 @@
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 @@
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;
}
More information about the llvm-commits
mailing list