mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
raw pointers replaced with smart pointers
This commit is contained in:
parent
c774a76f24
commit
cf1d72745c
@ -5,6 +5,7 @@
|
||||
#include <time.h>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#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<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;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "scratch.h"
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
|
||||
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<u8 []> 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<std::chrono::microseconds>(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);
|
||||
}
|
@ -6,14 +6,15 @@
|
||||
#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;
|
||||
@ -29,8 +30,8 @@ void shufti_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 = shuftiExec(lo, hi, kt1, kt1 + size);
|
||||
act_size += res - kt1;
|
||||
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();
|
||||
@ -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<std::chrono::microseconds>(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<u8 []> 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<std::chrono::microseconds>(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<std::chrono::microseconds>(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;
|
||||
}
|
||||
|
@ -5,14 +5,15 @@
|
||||
#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;
|
||||
@ -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<std::chrono::microseconds>(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<std::chrono::microseconds>(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<u8 []> 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<std::chrono::microseconds>(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<std::chrono::microseconds>(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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user