#include <iostream>
#include <string.h>
#include <string>
#include <benchmark/benchmark.h>
std::string mystr;
void init_mystr() {
mystr = "hello world.";
}
void test0() {
std::string str = mystr;
str.size();
}
static void BM_demo(benchmark::State &state) {
init_mystr();
for (auto _ : state) {
test0();
}
}
static void BM_memcpy(benchmark::State &state) {
size_t size = state.range(0);
char *src_str = (char *)malloc(size);
char *dest_str = (char *)malloc(size);
memset(src_str, 'A', size);
for (auto _ : state) {
memcpy(dest_str, src_str, size);
}
state.SetBytesProcessed(size * (uint64_t)(state.iterations()));
free(src_str);
free(dest_str);
}
//BENCHMARK(BM_demo);
BENCHMARK(BM_memcpy)->Iterations(1000000)->Arg(8)->Arg(64)->Arg(128)->Arg(512)->Arg(1024)->Arg(2048)->Arg(4196);
BENCHMARK_MAIN();
//g++ -o Test test.cpp -std=c++11 -lpthread -lbenchmark