exit(1);
}
- DoTest();
+ printf("%15s\t%15s\t%15s\t\t%15s\t\t%15s\n", "Iterations", "Data size",
+ "Time", "Throughput", "Latency");
+ if (options_->IsAll()) {
+ DoTest(4000, 10);
+ DoTest(4000, 20);
+ DoTest(4000, 100);
+ DoTest(4000, 200);
+ DoTest(2000, 1000);
+ DoTest(2000, 2000);
+ DoTest(1000, 10000);
+ DoTest(1000, 20000);
+ DoTest(1000, 30000);
+ DoTest(1000, 40000);
+ DoTest(1000, 50000);
+ DoTest(1000, 60000);
+ DoTest(500, 100000);
+ } else {
+ DoTest(options_->GetIters(), options_->GetSize());
+ }
}
private:
- void DoTest() {
- int iters = options_->GetIters();
- int size = options_->GetSize();
+ void DoTest(int iters, int size) {
+ bool is_func = options_->IsFunction();
StartTime();
for (int i = 0; i < iters; i++) {
+ if (is_func) {
+ int ret = FakeFunction(std::string(size, 'a'));
+ if (ret != 0) {
+ _E("Invalid return");
+ break;
+ }
+
+ continue;
+ }
+
int ret = proxy_->Test(std::string(size, 'a'));
if (ret != 0) {
_E("Invalid return");
break;
}
}
- EndTime();
+ EndTime(iters, size);
+ }
+
+ int FakeFunction(std::string str) {
+ return 0;
}
void StartTime() {
start_ = std::chrono::system_clock::now();
}
- void EndTime() {
+ void EndTime(int iters, int size) {
std::chrono::duration<double> sec = std::chrono::system_clock::now() - start_;
- std::cout << "Iterations: " << std::to_string(options_->GetIters()) << std::endl;
- std::cout << "Data size: " << std::to_string(options_->GetSize()) << "Byte" << std::endl;
- std::cout << "Duration: " << sec.count() << "s" << std::endl;
- double t = options_->GetSize() * options_->GetIters() / sec.count() / 1024 / 1024;
- std::cout << "Throughput: " << std::to_string(t * 8) << "Mb/s" << std::endl;
- double l = sec.count() * 1000 / options_->GetIters();
- std::cout << "Latency: " << std::to_string(l) << "ms" << std::endl;
+ double t = size * iters * 8 / sec.count() / 1024 / 1024;
+ double l = sec.count() * 1000 / iters;
+
+ printf("%10d\t%10dByte\t%15.4fs\t%15.4fMb/s\t%15.4fms\n", iters, size,
+ sec.count(), t, l);
}
void ExecuteServer() {
-h, --help Show help options
Additional Options:
+ -f, --funcation Use function call instead of RPC
+ -a, --all Test pre-defined test-cases
-i, --interations=<Iterations> Iterations
-s, --size=<Data size> Data size (byte)
}
std::unique_ptr<Options> Options::Parse(int argc, char** argv) {
- int cmd[CMD_MAX] = { 0, };
- int opt[OPT_MAX] = { 0, };
+ bool cmd[CMD_MAX] = { false, };
+ bool opt[OPT_MAX] = { false, };
auto options = std::unique_ptr<Options>(new Options());
int option_index = 0;
{"help", no_argument, nullptr, 'h'},
{"iterations", required_argument, nullptr, 'i'},
{"size", required_argument, nullptr, 's'},
+ {"function", no_argument, nullptr, 'f'},
+ {"all", no_argument, nullptr, 'a'},
{0, 0, 0, 0}
};
while (true) {
- int c = getopt_long(argc, argv, "vhi:s:", long_options,
+ int c = getopt_long(argc, argv, "vhfai:s:", long_options,
&option_index);
if (c == -1)
break;
break;
case 'v':
- cmd[CMD_VERSION] = 1;
+ cmd[CMD_VERSION] = true;
break;
case 'h':
- cmd[CMD_HELP] = 1;
+ cmd[CMD_HELP] = true;
break;
case 'i':
- opt[OPT_ITER] = 1;
+ opt[OPT_ITER] = true;
options->iters_ = std::stoi(optarg);
break;
case 's':
- opt[OPT_SIZE] = 1;
+ opt[OPT_SIZE] = true;
options->size_ = std::stoi(optarg);
break;
+ case 'f':
+ opt[OPT_FUNCTION] = true;
+ options->is_function_ = true;
+ break;
+
+ case 'a':
+ opt[OPT_ALL] = true;
+ options->is_all_ = true;
+ break;
+
default:
- cmd[CMD_HELP] = 1;
+ cmd[CMD_HELP] = true;
}
}
if (cmd[CMD_HELP]) {
options->PrintUsage();
return std::unique_ptr<Options>(nullptr);
+ } else if (opt[OPT_ALL]) {
+ return options;
} else if (!opt[OPT_ITER] || !opt[OPT_SIZE]) {
options->PrintSample();
return std::unique_ptr<Options>(nullptr);