#include <time.h>
#include <functional>
#include <vector>
+#include <memory>
#define MAX_LOOPS 500000000
#define MAX_MATCHES 10
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);
}
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<char []> str ( new char[char_len] );
for (int j=0; j<char_len; j++) {
srand (time(NULL));
int key = rand() % + 36 ;
str[char_len] = charset[key];
str[char_len + 1] = '\0';
}
- noodle_benchmarks(sizes[i], MAX_LOOPS / sizes[i], str,char_len, 0);
- delete [] str;
+ noodle_benchmarks(sizes[i], MAX_LOOPS / sizes[i], str.get(), char_len, 0);
}
}
return 0;
#include "scratch.h"
#include <vector>
#include <chrono>
+#include <memory>
struct hlmMatchEntry {
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<u8 []> data ( new u8[size] );
+ memset(data.get(), 'a', size);
double total_sec = 0.0;
u64a transferred_size = 0;
double avg_time = 0.0;
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<std::chrono::microseconds>(end - start).count();
/*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
#include <cstring>
#include <ctime>
#include <cstdlib>
+#include <memory>
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<u8 []> kt1 ( new u8[size] );
+ memset(kt1.get(),'b',size);
double total_sec = 0.0;
u64a transferred_size = 0;
double bandwitdh = 0.0;
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<std::chrono::microseconds>(end - start).count();
} 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<std::chrono::microseconds>(end - start).count();
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) {
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<u8 []> kt1 ( new u8[size] );
+ memset(kt1.get(),'b',size);
double total_sec = 0.0;
u64a transferred_size = 0;
double bandwitdh = 0.0;
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<std::chrono::microseconds>(end - start).count();
} 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<std::chrono::microseconds>(end - start).count();
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;
}
#include <chrono>
#include <cstring>
#include <ctime>
+#include <memory>
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<u8 []> kt1 ( new u8[size] );
+ memset(kt1.get(),'b',size);
double total_sec = 0.0;
u64a transferred_size = 0;
double bandwitdh = 0.0;
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<std::chrono::microseconds>(end - start).count();
} 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<std::chrono::microseconds>(end - start).count();
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;
}
ue2::CharReach chars;
chars.set('a');
truffleBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
- u8 *kt1 = new u8[size];
- memset(kt1,'b',size);
+ std::unique_ptr<u8 []> kt1 ( new u8[size] );
+ memset(kt1.get(),'b',size);
double total_sec = 0.0;
u64a transferred_size = 0;
double bandwitdh = 0.0;
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<std::chrono::microseconds>(end - start).count();
} 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<std::chrono::microseconds>(end - start).count();
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;
}