diff --git a/benchmarks/benchmarks.cpp b/benchmarks/benchmarks.cpp index 81435891..be224ba9 100644 --- a/benchmarks/benchmarks.cpp +++ b/benchmarks/benchmarks.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #define MAX_LOOPS 500000000 #define MAX_MATCHES 10 @@ -14,7 +15,7 @@ int main(){ int sizes[] = { 16000, 32000, 64000, 120000, 1600000, 2000000, 2500000, 3500000, 150000000, 250000000, 350000000, 500000000 }; const char charset[] = "aAaAaAaAAAaaaaAAAAaaaaAAAAAAaaaAAaaa"; for (size_t i = 0; i < std::size(sizes); i++) { - for(int j = 0; j < 4; j++) { + for(size_t j = 0; j < std::size(functions); j++) { functions[j](sizes[i], MAX_LOOPS / sizes[i], MAX_MATCHES, false); functions[j](sizes[i], MAX_LOOPS / sizes[i], MAX_MATCHES, true); } @@ -22,15 +23,14 @@ int main(){ for(size_t i=0; i < std::size(sizes); i++){ //we imitate the noodle unit tests for (int char_len = 1; char_len < 9; char_len++) { - char *str = new char[char_len]; + std::unique_ptr str ( new char[char_len] ); for (int j=0; j #include +#include struct hlmMatchEntry { @@ -31,8 +32,8 @@ hwlmcb_rv_t hlmSimpleCallback(size_t to, u32 id, void noodle_benchmarks(int size, int loops, const char *lit_str, int lit_len, char nocase){ ctxt.clear(); - u8 *data = new u8[size]; - memset(data, 'a', size); + std::unique_ptr data ( new u8[size] ); + memset(data.get(), 'a', size); double total_sec = 0.0; u64a transferred_size = 0; double avg_time = 0.0; @@ -45,7 +46,7 @@ void noodle_benchmarks(int size, int loops, const char *lit_str, int lit_len, ch struct hs_scratch scratch; auto start = std::chrono::steady_clock::now(); for (int i = 0; i < loops; i++){ - noodExec(n.get(), data, size, 0, hlmSimpleCallback, &scratch); + noodExec(n.get(), data.get(), size, 0, hlmSimpleCallback, &scratch); } auto end = std::chrono::steady_clock::now(); total_sec += std::chrono::duration_cast(end - start).count(); @@ -62,7 +63,6 @@ void noodle_benchmarks(int size, int loops, const char *lit_str, int lit_len, ch /*calculate average bandwidth*/ bandwitdh = max_bw / loops; printf(KMAG "Case with %u matches in random pos with %u * %u iterations," KBLU " total elapsed time =" RST " %.3f s, " - KBLU "average time per call =" RST " %.3f μs," KBLU " bandwidth = " RST " %.3f MB/s," KBLU " average bandwidth =" RST " %.3f MB/s \n", - lit_len, size ,loops, total_sec, avg_time, max_bw, bandwitdh); - delete [] data; + KBLU "average time per call =" RST " %.3f μs," KBLU " bandwidth = " RST " %.3f MB/s," KBLU " average bandwidth =" RST " %.3f MB/s \n", + lit_len, size ,loops, total_sec, avg_time, max_bw, bandwitdh); } \ No newline at end of file diff --git a/benchmarks/shufti.cpp b/benchmarks/shufti.cpp index d170bfcf..f6c2be5c 100644 --- a/benchmarks/shufti.cpp +++ b/benchmarks/shufti.cpp @@ -6,14 +6,15 @@ #include #include #include +#include void shufti_benchmarks(int size, int loops, int M, bool has_match) { m128 lo, hi; ue2::CharReach chars; chars.set('a'); int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi); - u8 *kt1 = new u8[size]; - memset(kt1,'b',size); + std::unique_ptr kt1 ( new u8[size] ); + memset(kt1.get(),'b',size); double total_sec = 0.0; u64a transferred_size = 0; double bandwitdh = 0.0; @@ -28,9 +29,9 @@ void shufti_benchmarks(int size, int loops, int M, bool has_match) { kt1[pos] = 'a'; unsigned long act_size = 0; auto start = std::chrono::steady_clock::now(); - for(int i = 0; i < loops; i++) { - const u8 *res = shuftiExec(lo, hi, kt1, kt1 + size); - act_size += res - kt1; + for(int i = 0; i < loops; i++) { + const u8 *res = shuftiExec(lo, hi, kt1.get(), kt1.get() + size); + act_size += res - kt1.get(); } auto end = std::chrono::steady_clock::now(); double dt = std::chrono::duration_cast(end - start).count(); @@ -55,7 +56,7 @@ void shufti_benchmarks(int size, int loops, int M, bool has_match) { } else { auto start = std::chrono::steady_clock::now(); for (int i = 0; i < loops; i++) { - shuftiExec(lo, hi, kt1, kt1 + size); + shuftiExec(lo, hi, kt1.get(), kt1.get() + size); } auto end = std::chrono::steady_clock::now(); total_sec += std::chrono::duration_cast(end - start).count(); @@ -75,7 +76,6 @@ void shufti_benchmarks(int size, int loops, int M, bool has_match) { KBLU "average time per call =" RST " %.3f μs ," KBLU " bandwidth = " RST " %.3f MB/s," KBLU " average bandwidth =" RST " %.3f MB/s \n", size ,loops, total_sec, avg_time, max_bw, bandwitdh); } - delete [] kt1; } void rshufti_benchmarks(int size, int loops, int M, bool has_match) { @@ -83,8 +83,8 @@ void rshufti_benchmarks(int size, int loops, int M, bool has_match) { ue2::CharReach chars; chars.set('a'); int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi); - u8 *kt1 = new u8[size]; - memset(kt1,'b',size); + std::unique_ptr kt1 ( new u8[size] ); + memset(kt1.get(),'b',size); double total_sec = 0.0; u64a transferred_size = 0; double bandwitdh = 0.0; @@ -100,8 +100,8 @@ void rshufti_benchmarks(int size, int loops, int M, bool has_match) { unsigned long act_size = 0; auto start = std::chrono::steady_clock::now(); for(int i = 0; i < loops; i++) { - const u8 *res = rshuftiExec(lo, hi, kt1, kt1 + size); - act_size += res - kt1; + const u8 *res = rshuftiExec(lo, hi, kt1.get(), kt1.get() + size); + act_size += res - kt1.get(); } auto end = std::chrono::steady_clock::now(); double dt = std::chrono::duration_cast(end - start).count(); @@ -126,7 +126,7 @@ void rshufti_benchmarks(int size, int loops, int M, bool has_match) { } else { auto start = std::chrono::steady_clock::now(); for (int i = 0; i < loops; i++) { - rshuftiExec(lo, hi, kt1, kt1 + size); + rshuftiExec(lo, hi, kt1.get(), kt1.get() + size); } auto end = std::chrono::steady_clock::now(); total_sec += std::chrono::duration_cast(end - start).count(); @@ -146,5 +146,4 @@ void rshufti_benchmarks(int size, int loops, int M, bool has_match) { KBLU "average time per call =" RST " %.3f μs ," KBLU " bandwidth = " RST " %.3f MB/s," KBLU " average bandwidth =" RST " %.3f MB/s \n", size ,loops, total_sec, avg_time, max_bw, bandwitdh); } - delete [] kt1; } diff --git a/benchmarks/truffle.cpp b/benchmarks/truffle.cpp index 077cadba..d521c2b1 100644 --- a/benchmarks/truffle.cpp +++ b/benchmarks/truffle.cpp @@ -5,14 +5,15 @@ #include #include #include +#include void truffle_benchmarks(int size, int loops, int M, bool has_match) { m128 lo, hi; ue2::CharReach chars; chars.set('a'); truffleBuildMasks(chars, (u8 *)&lo, (u8 *)&hi); - u8 *kt1 = new u8[size]; - memset(kt1,'b',size); + std::unique_ptr kt1 ( new u8[size] ); + memset(kt1.get(),'b',size); double total_sec = 0.0; u64a transferred_size = 0; double bandwitdh = 0.0; @@ -28,8 +29,8 @@ void truffle_benchmarks(int size, int loops, int M, bool has_match) { unsigned long act_size = 0; auto start = std::chrono::steady_clock::now(); for(int i = 0; i < loops; i++) { - const u8 *res = truffleExec(lo, hi, kt1, kt1 + size); - act_size += res - kt1; + const u8 *res = truffleExec(lo, hi, kt1.get(), kt1.get() + size); + act_size += res - kt1.get(); } auto end = std::chrono::steady_clock::now(); double dt = std::chrono::duration_cast(end - start).count(); @@ -54,7 +55,7 @@ void truffle_benchmarks(int size, int loops, int M, bool has_match) { } else { auto start = std::chrono::steady_clock::now(); for (int i = 0; i < loops; i++) { - truffleExec(lo, hi, kt1, kt1 + size); + truffleExec(lo, hi, kt1.get(), kt1.get() + size); } auto end = std::chrono::steady_clock::now(); total_sec += std::chrono::duration_cast(end - start).count(); @@ -74,7 +75,6 @@ void truffle_benchmarks(int size, int loops, int M, bool has_match) { KBLU "average time per call =" RST " %.3f μs ," KBLU " bandwidth = " RST " %.3f MB/s," KBLU " average bandwidth =" RST " %.3f MB/s \n", size ,loops, total_sec, avg_time, max_bw, bandwitdh); } - delete [] kt1; } @@ -83,8 +83,8 @@ void rtruffle_benchmarks(int size, int loops, int M, bool has_match) { ue2::CharReach chars; chars.set('a'); truffleBuildMasks(chars, (u8 *)&lo, (u8 *)&hi); - u8 *kt1 = new u8[size]; - memset(kt1,'b',size); + std::unique_ptr kt1 ( new u8[size] ); + memset(kt1.get(),'b',size); double total_sec = 0.0; u64a transferred_size = 0; double bandwitdh = 0.0; @@ -100,8 +100,8 @@ void rtruffle_benchmarks(int size, int loops, int M, bool has_match) { unsigned long act_size = 0; auto start = std::chrono::steady_clock::now(); for(int i = 0; i < loops; i++) { - const u8 *res = rtruffleExec(lo, hi, kt1, kt1 + size); - act_size += res - kt1; + const u8 *res = rtruffleExec(lo, hi, kt1.get(), kt1.get() + size); + act_size += res - kt1.get(); } auto end = std::chrono::steady_clock::now(); double dt = std::chrono::duration_cast(end - start).count(); @@ -126,7 +126,7 @@ void rtruffle_benchmarks(int size, int loops, int M, bool has_match) { } else { auto start = std::chrono::steady_clock::now(); for (int i = 0; i < loops; i++) { - rtruffleExec(lo, hi, kt1, kt1 + size); + rtruffleExec(lo, hi, kt1.get(), kt1.get() + size); } auto end = std::chrono::steady_clock::now(); total_sec += std::chrono::duration_cast(end - start).count(); @@ -146,5 +146,4 @@ void rtruffle_benchmarks(int size, int loops, int M, bool has_match) { KBLU "average time per call =" RST " %.3f μs ," KBLU " bandwidth = " RST " %.3f MB/s," KBLU " average bandwidth =" RST " %.3f MB/s \n", size ,loops, total_sec, avg_time, max_bw, bandwitdh); } - delete [] kt1; }