From 53b903454661aa36259f164a265407177fd72cf2 Mon Sep 17 00:00:00 2001 From: apostolos Date: Mon, 13 Sep 2021 20:25:46 +0300 Subject: [PATCH] bandwidth output fixes --- benchmarks/benchmarks.cpp | 29 +++++++------ benchmarks/noodle.cpp | 19 ++++++--- benchmarks/shufti.cpp | 89 +++++++++++++++++++++++---------------- benchmarks/truffle.cpp | 82 ++++++++++++++++++++++-------------- 4 files changed, 131 insertions(+), 88 deletions(-) diff --git a/benchmarks/benchmarks.cpp b/benchmarks/benchmarks.cpp index 4b961013..e391dfcf 100644 --- a/benchmarks/benchmarks.cpp +++ b/benchmarks/benchmarks.cpp @@ -6,23 +6,26 @@ #include int main(){ - int sizes[]= { 16000, 32000, 64000, 120000, 1600000, 2000000, 2500000, 3500000, 150000000, 250000000, 350000000, 500000000}; - int loops[]= { 6000, 6000, 6000, 6000, 1000, 1000, 1000, 1000, 50, 50, 25, 25}; - int exp_len[]= { 2000, 2000, 2000, 2000, 250, 250, 250, 250, 10, 10, 5, 5}; + int sizes[]= { 16000, 32000, 64000, 120000, 1600000, 2000000, 2500000, 3500000, 150000000, 250000000, 350000000, 500000000}; + int f_loops[]= { 70000, 50000, 30000, 10000, 1000, 1000, 1000, 1000, 7, 7, 5, 3}; + int t_loops[]= { 200000, 150000, 100000, 70000, 5000, 5000, 5000, 5000, 50, 50, 50, 50}; + int exp_len[]= { 15, 15, 15, 15, 5, 5, 5, 5, 5, 5, 5, 5}; + int nd_loops[]= { 250000, 150000, 100000, 100000, 10000, 1000, 1000, 1000, 100, 100, 100, 100}; const char charset[] = "aAaAaAaAAAaaaaAAAAaaaaAAAAAAaaaAAaaa"; - std::string labels[] = {"\x1B[33m shuftiExec Benchmarks(kbytes) \x1B[0m\n", "\x1B[33m rshuftiExec Benchmarks(kbytes) \x1B[0m\n", - "\x1B[33m truffleExec Benchmarks(kbytes) \x1B[0m\n", "\x1B[33m rtruffleExec Benchmarks(kbytes) \x1B[0m\n", - "\x1B[33m shuftiExec Benchmarks(Mbytes) \x1B[0m\n", "\x1B[33m rhuftiExec Benchmarks(Mbytes) \x1B[0m\n", - "\x1B[33m truffleExec Benchmarks(Mbytes) \x1B[0m\n", "\x1B[33m rtruffleExec Benchmarks(Mbytes) \x1B[0m\n", - "\x1B[33m shuftiExec Benchmarks(Gbytes) \x1B[0m\n", "\x1B[33m rhuftiExec Benchmarks(Gbytes) \x1B[0m\n", - "\x1B[33m truffleExec Benchmarks(Gbytes) \x1B[0m\n", "\x1B[33m rtruffleExec Benchmarks(Gbytes) \x1B[0m\n" + std::string labels[] = {"\x1B[33m Benchmarks(kbytes) \x1B[0m\n", "\x1B[33m Benchmarks(kbytes) \x1B[0m\n", + "\x1B[33m Benchmarks(kbytes) \x1B[0m\n", "\x1B[33m Benchmarks(kbytes) \x1B[0m\n", + "\x1B[33m Benchmarks(Mbytes) \x1B[0m\n", "\x1B[33m Benchmarks(Mbytes) \x1B[0m\n", + "\x1B[33m Benchmarks(Mbytes) \x1B[0m\n", "\x1B[33m Benchmarks(Mbytes) \x1B[0m\n", + "\x1B[33m Benchmarks(Gbytes) \x1B[0m\n", "\x1B[33m Benchmarks(Gbytes) \x1B[0m\n", + "\x1B[33m Benchmarks(Gbytes) \x1B[0m\n", "\x1B[33m Benchmarks(Gbytes) \x1B[0m\n" }; + std::function functions[] = { shufti_benchmarks, rshufti_benchmarks, truffle_benchmarks, rtruffle_benchmarks }; - for (int i=0; i<12; i++) { + for (int i=11; i<12; i++) { std::cout << labels[i]; for(int j=0; j<4; j++){ - functions[j](sizes[i],loops[i],exp_len[i],false); - functions[j](sizes[i],loops[i],exp_len[i],true); + functions[j](sizes[i],f_loops[i],exp_len[i],false); + functions[j](sizes[i],t_loops[i],exp_len[i],true); } } for(int i=0; i<12; i++){ @@ -43,7 +46,7 @@ int main(){ str[char_len] = charset[key]; str[char_len + 1] = '\0'; } - noodle_benchmarks(sizes[i], loops[i], str,char_len,0); + noodle_benchmarks(sizes[i], nd_loops[i], str,char_len,0); delete [] str; } } diff --git a/benchmarks/noodle.cpp b/benchmarks/noodle.cpp index 3ac37ffa..a910e0cf 100644 --- a/benchmarks/noodle.cpp +++ b/benchmarks/noodle.cpp @@ -33,7 +33,8 @@ void noodle_benchmarks(int size, int M, const char *lit_str, int lit_len, char n ctxt.clear(); u8 *data = new u8[size]; memset(data, 'a', size); - double total_sec = 0; + long double total_sec = 0; + long double trans_size = 0; long double bw = 0; u32 id = 1000; ue2::hwlmLiteral lit(std::string(lit_str, lit_len), nocase, id); @@ -45,12 +46,16 @@ void noodle_benchmarks(int size, int M, const char *lit_str, int lit_len, char n noodExec(n.get(), data, size, 0, hlmSimpleCallback, &scratch); } auto end = std::chrono::steady_clock::now(); - total_sec += std::chrono::duration_cast(end - start).count(); - /*average time*/ - total_sec /= M; - double mb_size = (double) size / 1048576; - bw = mb_size / total_sec; + total_sec += std::chrono::duration_cast(end - start).count(); + /*calculate transferred size*/ + trans_size = size * M; + /*convert to sec*/ + bw = trans_size / total_sec; + /*convert to MB/s*/ + bw /=1048576; + /*covert average time to μs*/ + long double ms = total_sec * 1000000; std::cout << "\x1B[35m Case with match in random pos and size: "<< size <<" lit_len: "<< lit_len <<" nocase: "<< (int)nocase - << "\x1B[36m noodExec elapsetime: \x1B[0m" << total_sec << " (μs) \x1B[36m bandwidth: \x1B[0m" << bw <<" (MB/μs)" << std::endl; + << "\x1B[36m noodExec elapsetime: \x1B[0m" << (ms/M) << " (μs) \x1B[36m bandwidth: \x1B[0m" << bw <<" (MB/s)" << std::endl; delete [] data; } \ No newline at end of file diff --git a/benchmarks/shufti.cpp b/benchmarks/shufti.cpp index 934f485d..ce576a0f 100644 --- a/benchmarks/shufti.cpp +++ b/benchmarks/shufti.cpp @@ -27,8 +27,9 @@ void shufti_benchmarks(int size, int loops, int M, bool has_match) { int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi); u8 *kt1 = new u8[size]; memset(kt1,'b',size); - double total_sec = 0; - double bw = 0; + long double total_sec = 0; + long double trans_size = 0; + long double bw = 0; if (has_match){ int pos = 0; for(int j=0; j(end - start).count(); - /*average time*/ - dt /= loops; + long double dt = std::chrono::duration_cast(end - start).count(); total_sec += dt; - /*average size*/ - act_size /= loops; - double mb_size = (double) act_size / 1048576; - bw += mb_size / dt; + /*calculate transferred size*/ + trans_size += act_size * loops; + /*calculate bandwidth*/ + bw += trans_size / total_sec; + /*convert to MB/s*/ + bw += bw / 1048576; + /*calculte average time*/ + total_sec /= loops; } total_sec /= M; bw /= M; - std::cout << "\x1B[35m Case with match in random pos and size: " << real_size << " for " << loops <<" loops (" - << M << " random possisions checked): \x1B[36m shuftiExec elapsetime: \x1B[0m" << (total_sec) - << " (μs) \x1B[36m bandwidth: \x1B[0m" << bw <<" (MB/μs)"<(end - start).count(); - /*average time*/ - total_sec /= loops; - double mb_size = (double) size / 1048576; - mb_size /= loops; - bw = mb_size / total_sec; + total_sec += std::chrono::duration_cast(end - start).count(); + /*calculate transferred size*/ + trans_size = size * loops ; + /*calculate bandwidth*/ + bw = trans_size / total_sec; + /*convert to MB/s*/ + bw /=1048576; + /*covert average time to μs*/ + long double ms = total_sec * 1000000; std::cout<<"\x1B[35m Case with no match in random pos and size: "<(end - start).count(); - /*average time*/ - dt /= loops; + long double dt = std::chrono::duration_cast(end - start).count(); total_sec += dt; - /*average size*/ - act_size /= loops; - double mb_size = (double) act_size / 1048576; - bw += mb_size / dt; + /*calculate transferred size*/ + trans_size += act_size * loops; + /*calculate bandwidth*/ + bw += trans_size / total_sec; + /*convert to MB/s*/ + bw += bw / 1048576; + /*calculte average time*/ + total_sec /= loops; } total_sec /= M; bw /= M; + /*covert average time to μs*/ + long double ms = total_sec * 1000000; std::cout << "\x1B[35m Case with match in random pos and size: " << real_size << " for " << loops<<" loops (" - << M << " random possisions checked): \x1B[36m rshuftiExec elapsetime: \x1B[0m" << total_sec - <<" (μs) \x1B[36m bandwidth: \x1B[0m" << bw <<" (MB/μs)"<(end - start).count(); - /*average time*/ - total_sec /=loops; - double mb_size = (double) size / 1048576; - bw = mb_size / total_sec; - std::cout<<"\x1B[35m Case with no match in random pos and size: "<< real_size <<" for "<< loops <<" loops:" - <<"\x1B[36m rshuftiExec elapsetime: \x1B[0m"<< total_sec <<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/μs)"<(end - start).count(); + /*calculate transferred size*/ + trans_size = size * loops ; + /*calculate bandwidth*/ + bw = trans_size / total_sec; + /*convert to MB/s*/ + bw /=1048576; + /*covert average time to μs*/ + long double ms = total_sec * 1000000; + std::cout<<"\x1B[35m Case with no match in random pos and size: "<(end - start).count(); - /*average time*/ - dt /= loops; + long double dt = std::chrono::duration_cast(end - start).count(); total_sec += dt; - /*average size*/ - act_size /= loops; - double mb_size = (double) act_size / 1048576; - bw += mb_size / dt; + /*calculate transferred size*/ + trans_size += act_size * loops; + /*calculate bandwidth*/ + bw += trans_size / total_sec; + /*convert to MB/s*/ + bw += bw / 1048576; + /*calculte average time*/ + total_sec /= loops; } total_sec /= M; bw /= M; + /*covert average time to μs*/ + long double ms = total_sec * 1000000; std::cout << "\x1B[35m Case with match in random pos and size: " << real_size << " for "<< loops <<" loops (" - << M <<" random possisions checked): \x1B[36m truffleExec elapsetime: \x1B[0m" << total_sec + << M <<" random possisions checked): \x1B[36m truffleExec elapsetime: \x1B[0m" << (ms/M) << "(μs) \x1B[36m bandwidth: \x1B[0m"<< bw << "(MB/μs)" <(end - start).count(); - /*average time*/ - total_sec /= loops; - double mb_size = (double) size / 1048576; - bw = mb_size / total_sec; - std::cout<<"\x1B[35m Case with no match in random pos and size: "<< real_size <<" for "<< loops <<" loops:" - <<"\x1B[36m truffleExec elapsetime: \x1B[0m" << total_sec << " μs \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/μs)"<(end - start).count(); + /*calculate transferred size*/ + trans_size = size * loops ; + /*calculate bandwidth*/ + bw = trans_size / total_sec; + /*convert to MB/s*/ + bw /=1048576; + /*covert average time to μs*/ + long double ms = total_sec * 1000000; + std::cout<<"\x1B[35m Case with no match in random pos and size: "<(end - start).count(); - /*average time*/ - dt /= loops; + long double dt = std::chrono::duration_cast(end - start).count(); total_sec += dt; - /*average size*/ - act_size /= loops; - double mb_size = (double) act_size / 1048576; - bw += mb_size / dt; + /*calculate transferred size*/ + trans_size += act_size * loops; + /*calculate bandwidth*/ + bw += trans_size / total_sec; + /*convert to MB/s*/ + bw += bw / 1048576; + /*calculte average time*/ + total_sec /= loops; } total_sec /= M; bw /= M; + /*covert average time to μs*/ + long double ms = total_sec * 1000000; std::cout<<"\x1B[35m Case with match in random pos and size: "<< real_size <<" for "<(end - start).count(); - /*average time*/ - total_sec /= loops; - double mb_size = (double) size / 1048576; - bw = mb_size / total_sec; - std::cout<<"\x1B[35m Case with no match in random pos and size: "<< real_size <<" for "<< loops <<" loops:" - <<"\x1B[36m rtruffleExec elapsetime: \x1B[0m" << total_sec <<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/μs)"<(end - start).count(); + /*calculate transferred size*/ + trans_size = size * loops ; + /*calculate bandwidth*/ + bw = trans_size / total_sec; + /*convert to MB/s*/ + bw /=1048576; + /*covert average time to μs*/ + long double ms = total_sec * 1000000; + std::cout<<"\x1B[35m Case with no match in random pos and size: "<