mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
fix benchmarks outputs
This commit is contained in:
parent
53b9034546
commit
ee8fa17351
@ -4,40 +4,25 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define MAX_LOOPS 500000000
|
||||||
|
#define MAX_MATCHES 10
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
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 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<void(int,int,int,bool)> functions[] = { shufti_benchmarks, rshufti_benchmarks, truffle_benchmarks, rtruffle_benchmarks };
|
std::function<void(int,int,int,bool)> functions[] = { shufti_benchmarks, rshufti_benchmarks, truffle_benchmarks, rtruffle_benchmarks };
|
||||||
for (int i=11; i<12; i++) {
|
int sizes[] = { 16000, 32000, 64000, 120000, 1600000, 2000000, 2500000, 3500000, 150000000, 250000000, 350000000, 500000000 };
|
||||||
std::cout << labels[i];
|
const char charset[] = "aAaAaAaAAAaaaaAAAAaaaaAAAAAAaaaAAaaa";
|
||||||
for(int j=0; j<4; j++){
|
/*
|
||||||
functions[j](sizes[i],f_loops[i],exp_len[i],false);
|
for (size_t i = 0; i < std::size(sizes); i++) {
|
||||||
functions[j](sizes[i],t_loops[i],exp_len[i],true);
|
for(int j = 0; j < 4; j++) {
|
||||||
|
functions[j](sizes[i], MAX_LOOPS / sizes[i], MAX_MATCHES, false);
|
||||||
|
functions[j](sizes[i], MAX_LOOPS / sizes[i], MAX_MATCHES, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int i=0; i<12; i++){
|
*/
|
||||||
if(i==0){
|
for(size_t i=0; i < std::size(sizes); i++){
|
||||||
std::cout<<std::endl <<"\x1B[33m noodle Benchmarks(kbytes) \x1B[0m"<<std::endl;
|
//we imitate the noodle unit tests
|
||||||
}else if (i==4)
|
|
||||||
{
|
|
||||||
std::cout<<std::endl <<"\x1B[33m noodle Benchmarks(Mbytes) \x1B[0m"<<std::endl;
|
|
||||||
}else if (i==8)
|
|
||||||
{
|
|
||||||
std::cout<<std::endl <<"\x1B[33m noodle Benchmarks(Gbytes) \x1B[0m"<<std::endl;
|
|
||||||
}
|
|
||||||
for (int char_len = 1; char_len < 9; char_len++) {
|
for (int char_len = 1; char_len < 9; char_len++) {
|
||||||
char *str = new char[char_len];
|
char *str = new char[char_len];
|
||||||
for (int j=0; j<char_len; j++) {
|
for (int j=0; j<char_len; j++) {
|
||||||
@ -46,7 +31,7 @@ int main(){
|
|||||||
str[char_len] = charset[key];
|
str[char_len] = charset[key];
|
||||||
str[char_len + 1] = '\0';
|
str[char_len + 1] = '\0';
|
||||||
}
|
}
|
||||||
noodle_benchmarks(sizes[i], nd_loops[i], str,char_len,0);
|
noodle_benchmarks(sizes[i], MAX_LOOPS / sizes[i], str,char_len, 0);
|
||||||
delete [] str;
|
delete [] str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,13 @@
|
|||||||
|
/*define colour control characters*/
|
||||||
|
#define RST "\x1B[0m"
|
||||||
|
#define KRED "\x1B[31m"
|
||||||
|
#define KGRN "\x1B[32m"
|
||||||
|
#define KYEL "\x1B[33m"
|
||||||
|
#define KBLU "\x1B[34m"
|
||||||
|
#define KMAG "\x1B[35m"
|
||||||
|
#define KCYN "\x1B[36m"
|
||||||
|
#define KWHT "\x1B[37m"
|
||||||
|
|
||||||
void shufti_benchmarks(int size, int loops, int M, bool has_match);
|
void shufti_benchmarks(int size, int loops, int M, bool has_match);
|
||||||
void rshufti_benchmarks(int size, int loops, int M, bool has_match);
|
void rshufti_benchmarks(int size, int loops, int M, bool has_match);
|
||||||
void truffle_benchmarks(int size, int loops, int M, bool has_match);
|
void truffle_benchmarks(int size, int loops, int M, bool has_match);
|
||||||
|
@ -29,33 +29,40 @@ hwlmcb_rv_t hlmSimpleCallback(size_t to, u32 id,
|
|||||||
return HWLM_CONTINUE_MATCHING;
|
return HWLM_CONTINUE_MATCHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void noodle_benchmarks(int size, int M, const char *lit_str, int lit_len, char nocase){
|
void noodle_benchmarks(int size, int loops, const char *lit_str, int lit_len, char nocase){
|
||||||
ctxt.clear();
|
ctxt.clear();
|
||||||
u8 *data = new u8[size];
|
u8 *data = new u8[size];
|
||||||
memset(data, 'a', size);
|
memset(data, 'a', size);
|
||||||
long double total_sec = 0;
|
double total_sec = 0.0;
|
||||||
long double trans_size = 0;
|
u64a transferred_size = 0;
|
||||||
long double bw = 0;
|
double avg_time = 0.0;
|
||||||
|
double max_bw = 0.0;
|
||||||
|
double bandwitdh = 0.0;
|
||||||
u32 id = 1000;
|
u32 id = 1000;
|
||||||
ue2::hwlmLiteral lit(std::string(lit_str, lit_len), nocase, id);
|
ue2::hwlmLiteral lit(std::string(lit_str, lit_len), nocase, id);
|
||||||
auto n = ue2::noodBuildTable(lit);
|
auto n = ue2::noodBuildTable(lit);
|
||||||
assert(n != nullptr);
|
assert(n != nullptr);
|
||||||
struct hs_scratch scratch;
|
struct hs_scratch scratch;
|
||||||
auto start = std::chrono::steady_clock::now();
|
auto start = std::chrono::steady_clock::now();
|
||||||
for (int i = 0; i < M; i++){
|
for (int i = 0; i < loops; i++){
|
||||||
noodExec(n.get(), data, size, 0, hlmSimpleCallback, &scratch);
|
noodExec(n.get(), data, size, 0, hlmSimpleCallback, &scratch);
|
||||||
}
|
}
|
||||||
auto end = std::chrono::steady_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
total_sec += std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||||
/*calculate transferred size*/
|
/*calculate transferred size*/
|
||||||
trans_size = size * M;
|
transferred_size = size * loops;
|
||||||
/*convert to sec*/
|
/*calculate average time*/
|
||||||
bw = trans_size / total_sec;
|
avg_time = total_sec / loops;
|
||||||
|
/*convert microseconds to seconds*/
|
||||||
|
total_sec /= 1000000.0;
|
||||||
|
/*calculate maximum bandwidth*/
|
||||||
|
max_bw = transferred_size / total_sec;
|
||||||
/*convert to MB/s*/
|
/*convert to MB/s*/
|
||||||
bw /=1048576;
|
max_bw /=1048576.0;
|
||||||
/*covert average time to μs*/
|
/*calculate average bandwidth*/
|
||||||
long double ms = total_sec * 1000000;
|
bandwitdh = max_bw / loops;
|
||||||
std::cout << "\x1B[35m Case with match in random pos and size: "<< size <<" lit_len: "<< lit_len <<" nocase: "<< (int)nocase
|
printf(KMAG "Case with %u matches in random pos with %u * %u iterations," KBLU " total elapsed time =" RST " %.3f s, "
|
||||||
<< "\x1B[36m noodExec elapsetime: \x1B[0m" << (ms/M) << " (μs) \x1B[36m bandwidth: \x1B[0m" << bw <<" (MB/s)" << std::endl;
|
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;
|
delete [] data;
|
||||||
}
|
}
|
@ -7,142 +7,144 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
/*
|
|
||||||
#define RST "\x1B[0m"
|
|
||||||
#define KRED "\x1B[31m"
|
|
||||||
#define KGRN "\x1B[32m"
|
|
||||||
#define KYEL "\x1B[33m"
|
|
||||||
#define KBLU "\x1B[34m"
|
|
||||||
#define KMAG "\x1B[35m"
|
|
||||||
#define KCYN "\x1B[36m"
|
|
||||||
#define KWHT "\x1B[37m"
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
void shufti_benchmarks(int size, int loops, int M, bool has_match) {
|
void shufti_benchmarks(int size, int loops, int M, bool has_match) {
|
||||||
size_t real_size = size;
|
|
||||||
m128 lo, hi;
|
m128 lo, hi;
|
||||||
ue2::CharReach chars;
|
ue2::CharReach chars;
|
||||||
chars.set('a');
|
chars.set('a');
|
||||||
int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
|
int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
|
||||||
u8 *kt1 = new u8[size];
|
u8 *kt1 = new u8[size];
|
||||||
memset(kt1,'b',size);
|
memset(kt1,'b',size);
|
||||||
long double total_sec = 0;
|
double total_sec = 0.0;
|
||||||
long double trans_size = 0;
|
u64a transferred_size = 0;
|
||||||
long double bw = 0;
|
double bandwitdh = 0.0;
|
||||||
if (has_match){
|
double max_bw = 0.0;
|
||||||
|
double avg_time = 0.0;
|
||||||
|
if (has_match) {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for(int j=0; j<M; j++){
|
for(int j = 0; j < M; j++) {
|
||||||
kt1[pos] = 'b';
|
kt1[pos] = 'b';
|
||||||
srand (time(NULL));
|
srand (time(NULL));
|
||||||
pos = rand() % size + 0;
|
pos = rand() % size + 0;
|
||||||
kt1[pos] = 'a';
|
kt1[pos] = 'a';
|
||||||
unsigned long act_size = 0;
|
unsigned long act_size = 0;
|
||||||
auto start = std::chrono::steady_clock::now();
|
auto start = std::chrono::steady_clock::now();
|
||||||
for (int i = 0; i < loops; i++) {
|
for(int i = 0; i < loops; i++) {
|
||||||
const u8 *res = shuftiExec(lo, hi, kt1, kt1 + size);
|
const u8 *res = shuftiExec(lo, hi, kt1, kt1 + size);
|
||||||
act_size += res - kt1;
|
act_size += res - kt1;
|
||||||
}
|
}
|
||||||
auto end = std::chrono::steady_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
long double dt = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||||
total_sec += dt;
|
total_sec += dt;
|
||||||
/*calculate transferred size*/
|
/*convert microseconds to seconds*/
|
||||||
trans_size += act_size * loops;
|
total_sec /= 1000000.0;
|
||||||
/*calculate bandwidth*/
|
/*calculate bandwidth*/
|
||||||
bw += trans_size / total_sec;
|
bandwitdh += act_size / total_sec;
|
||||||
/*convert to MB/s*/
|
/*convert to MB/s*/
|
||||||
bw += bw / 1048576;
|
bandwitdh = bandwitdh / 1048576.0;
|
||||||
/*calculte average time*/
|
max_bw = std::max(bandwitdh ,max_bw);
|
||||||
total_sec /= loops;
|
/*calculate average time*/
|
||||||
|
avg_time += total_sec / loops;
|
||||||
}
|
}
|
||||||
total_sec /= M;
|
avg_time /= M;
|
||||||
bw /= M;
|
bandwitdh /= M;
|
||||||
/*covert average time to μs*/
|
/*convert average time to us*/
|
||||||
long double ms = total_sec * 1000000;
|
avg_time *= 1000000.0;
|
||||||
std::cout << "\x1B[35m Case with match in random pos and size: " << real_size << " for " << loops<<" loops ("
|
printf(KMAG "ShuftiExec: case with %u matches, %u * %u iterations," KBLU " total elapsed time =" RST " %.3f s, "
|
||||||
<< M << " random possisions checked): \x1B[36m shuftiExec elapsetime: \x1B[0m" << (ms/M)
|
KBLU "average time per call =" RST " %.3f μs," KBLU " bandwidth = " RST " %.3f MB/s," KBLU " average bandwidth =" RST " %.3f MB/s \n",
|
||||||
<<" (μs) \x1B[36m bandwidth: \x1B[0m" << bw <<" (MB/s)"<<std::endl;
|
M, size ,loops, total_sec, avg_time, max_bw, bandwitdh);
|
||||||
} else {
|
} else {
|
||||||
auto start = std::chrono::steady_clock::now();
|
auto start = std::chrono::steady_clock::now();
|
||||||
for (int i = 0; i < loops; i++) {
|
for (int i = 0; i < loops; i++) {
|
||||||
shuftiExec(lo, hi, kt1, kt1 + size);
|
shuftiExec(lo, hi, kt1, kt1 + size);
|
||||||
}
|
}
|
||||||
auto end = std::chrono::steady_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
total_sec += std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||||
/*calculate transferred size*/
|
/*calculate transferred size*/
|
||||||
trans_size = size * loops ;
|
transferred_size = size * loops;
|
||||||
/*calculate bandwidth*/
|
/*calculate average time*/
|
||||||
bw = trans_size / total_sec;
|
avg_time = total_sec / loops;
|
||||||
|
/*convert microseconds to seconds*/
|
||||||
|
total_sec /= 1000000.0;
|
||||||
|
/*calculate maximum bandwidth*/
|
||||||
|
max_bw = transferred_size / total_sec;
|
||||||
/*convert to MB/s*/
|
/*convert to MB/s*/
|
||||||
bw /=1048576;
|
max_bw /=1048576.0;
|
||||||
/*covert average time to μs*/
|
/*calculate average bandwidth*/
|
||||||
long double ms = total_sec * 1000000;
|
bandwitdh = max_bw / loops;
|
||||||
std::cout<<"\x1B[35m Case with no match in random pos and size: "<<real_size<<" for "<<loops<<" loops:"
|
printf(KMAG "ShuftiExec: case without matches, %u * %u iterations," KBLU " total elapsed time =" RST " %.3f s, "
|
||||||
<<"\x1B[36m shuftiExec elapsetime: \x1B[0m"<<(ms/loops)<<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/s)"<<std::endl;
|
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;
|
delete [] kt1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rshufti_benchmarks(int size, int loops, int M, bool has_match) {
|
void rshufti_benchmarks(int size, int loops, int M, bool has_match) {
|
||||||
size_t real_size = size;
|
|
||||||
m128 lo, hi;
|
m128 lo, hi;
|
||||||
ue2::CharReach chars;
|
ue2::CharReach chars;
|
||||||
chars.set('a');
|
chars.set('a');
|
||||||
int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
|
int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
|
||||||
u8 *kt1 = new u8[size];
|
u8 *kt1 = new u8[size];
|
||||||
memset(kt1,'b',size);
|
memset(kt1,'b',size);
|
||||||
long double total_sec = 0;
|
double total_sec = 0.0;
|
||||||
long double trans_size = 0;
|
u64a transferred_size = 0;
|
||||||
long double bw = 0;
|
double bandwitdh = 0.0;
|
||||||
if (has_match){
|
double max_bw = 0.0;
|
||||||
|
double avg_time = 0.0;
|
||||||
|
if (has_match) {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for(int j=0; j<M; j++){
|
for(int j = 0; j < M; j++) {
|
||||||
kt1[pos] = 'b';
|
kt1[pos] = 'b';
|
||||||
srand (time(NULL));
|
srand (time(NULL));
|
||||||
pos = rand() % size + 0;
|
pos = rand() % size + 0;
|
||||||
kt1[pos] = 'a';
|
kt1[pos] = 'a';
|
||||||
unsigned long act_size = 0;
|
unsigned long act_size = 0;
|
||||||
auto start = std::chrono::steady_clock::now();
|
auto start = std::chrono::steady_clock::now();
|
||||||
for (int i = 0; i < loops; i++) {
|
for(int i = 0; i < loops; i++) {
|
||||||
const u8 *res = rshuftiExec(lo, hi, kt1, kt1 + size);
|
const u8 *res = rshuftiExec(lo, hi, kt1, kt1 + size);
|
||||||
act_size += res - kt1;
|
act_size += res - kt1;
|
||||||
}
|
}
|
||||||
auto end = std::chrono::steady_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
long double dt = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||||
total_sec += dt;
|
total_sec += dt;
|
||||||
/*calculate transferred size*/
|
/*convert microseconds to seconds*/
|
||||||
trans_size += act_size * loops;
|
total_sec /= 1000000.0;
|
||||||
/*calculate bandwidth*/
|
/*calculate bandwidth*/
|
||||||
bw += trans_size / total_sec;
|
bandwitdh += act_size / total_sec;
|
||||||
/*convert to MB/s*/
|
/*convert to MB/s*/
|
||||||
bw += bw / 1048576;
|
bandwitdh = bandwitdh / 1048576.0;
|
||||||
/*calculte average time*/
|
max_bw = std::max(bandwitdh ,max_bw);
|
||||||
total_sec /= loops;
|
/*calculate average time*/
|
||||||
|
avg_time += total_sec / loops;
|
||||||
}
|
}
|
||||||
total_sec /= M;
|
avg_time /= M;
|
||||||
bw /= M;
|
bandwitdh /= M;
|
||||||
/*covert average time to μs*/
|
/*convert average time to μs*/
|
||||||
long double ms = total_sec * 1000000;
|
avg_time *= 1000000.0;
|
||||||
std::cout << "\x1B[35m Case with match in random pos and size: " << real_size << " for " << loops<<" loops ("
|
printf(KMAG "rShuftiExec: case with %u matches, %u * %u iterations," KBLU " total elapsed time =" RST " %.3f s, "
|
||||||
<< M << " random possisions checked): \x1B[36m rshuftiExec elapsetime: \x1B[0m" << (ms/M)
|
KBLU "average time per call =" RST " %.3f μs," KBLU " bandwidth = " RST " %.3f MB/s," KBLU " average bandwidth =" RST " %.3f MB/s \n",
|
||||||
<<" (μs) \x1B[36m bandwidth: \x1B[0m" << bw <<" (MB/s)"<<std::endl;
|
M, size ,loops, total_sec, avg_time, max_bw, bandwitdh);
|
||||||
} else {
|
} else {
|
||||||
auto start = std::chrono::steady_clock::now();
|
auto start = std::chrono::steady_clock::now();
|
||||||
for (int i = 0; i < loops; i++) {
|
for (int i = 0; i < loops; i++) {
|
||||||
rshuftiExec(lo, hi, kt1, kt1 + size);
|
rshuftiExec(lo, hi, kt1, kt1 + size);
|
||||||
}
|
}
|
||||||
auto end = std::chrono::steady_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
total_sec += std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||||
/*calculate transferred size*/
|
/*calculate transferred size*/
|
||||||
trans_size = size * loops ;
|
transferred_size = size * loops;
|
||||||
/*calculate bandwidth*/
|
/*calculate average time*/
|
||||||
bw = trans_size / total_sec;
|
avg_time = total_sec / loops;
|
||||||
|
/*convert microseconds to seconds*/
|
||||||
|
total_sec /= 1000000.0;
|
||||||
|
/*calculate maximum bandwidth*/
|
||||||
|
max_bw = transferred_size / total_sec;
|
||||||
/*convert to MB/s*/
|
/*convert to MB/s*/
|
||||||
bw /=1048576;
|
max_bw /=1048576.0;
|
||||||
/*covert average time to μs*/
|
/*calculate average bandwidth*/
|
||||||
long double ms = total_sec * 1000000;
|
bandwitdh = max_bw / loops;
|
||||||
std::cout<<"\x1B[35m Case with no match in random pos and size: "<<real_size<<" for "<<loops<<" loops:"
|
printf(KMAG "rShuftiExec: case without matches, %u * %u iterations," KBLU " total elapsed time =" RST " %.3f s, "
|
||||||
<<"\x1B[36m rshuftiExec elapsetime: \x1B[0m"<<(ms/loops)<<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/s)"<<std::endl;
|
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;
|
delete [] kt1;
|
||||||
}
|
}
|
||||||
|
@ -6,143 +6,145 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
/*
|
|
||||||
#define RST "\x1B[0m"
|
|
||||||
#define KRED "\x1B[31m"
|
|
||||||
#define KGRN "\x1B[32m"
|
|
||||||
#define KYEL "\x1B[33m"
|
|
||||||
#define KBLU "\x1B[34m"
|
|
||||||
#define KMAG "\x1B[35m"
|
|
||||||
#define KCYN "\x1B[36m"
|
|
||||||
#define KWHT "\x1B[37m"
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
void truffle_benchmarks(int size, int loops, int M, bool has_match) {
|
void truffle_benchmarks(int size, int loops, int M, bool has_match) {
|
||||||
size_t real_size = size;
|
|
||||||
m128 lo, hi;
|
|
||||||
ue2::CharReach chars;
|
|
||||||
chars.set('a');
|
|
||||||
truffleBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
|
|
||||||
u8*kt1 = new u8[size];
|
|
||||||
memset(kt1,'b',size);
|
|
||||||
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<M; j++){
|
|
||||||
kt1[pos] = 'b';
|
|
||||||
srand (time(NULL));
|
|
||||||
pos = rand() % size + 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 = truffleExec(lo, hi, kt1, kt1 + size);
|
|
||||||
act_size += res - kt1;
|
|
||||||
}
|
|
||||||
auto end = std::chrono::steady_clock::now();
|
|
||||||
long double dt = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
|
||||||
total_sec += 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" << (ms/M)
|
|
||||||
<< "(μs) \x1B[36m bandwidth: \x1B[0m"<< bw << "(MB/μs)" <<std::endl;
|
|
||||||
} else {
|
|
||||||
auto start = std::chrono::steady_clock::now();
|
|
||||||
for (int i = 0; i < loops; i++) {
|
|
||||||
truffleExec(lo, hi, kt1, kt1 + size);
|
|
||||||
}
|
|
||||||
auto end = std::chrono::steady_clock::now();
|
|
||||||
total_sec += std::chrono::duration_cast<std::chrono::seconds>(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: "<<real_size<<" for "<<loops<<" loops:"
|
|
||||||
<<"\x1B[36m truffleExec elapsetime: \x1B[0m"<<(ms/loops)<<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/s)"<<std::endl;
|
|
||||||
}
|
|
||||||
delete [] kt1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void rtruffle_benchmarks(int size, int loops, int M, bool has_match) {
|
|
||||||
size_t real_size = size;
|
|
||||||
m128 lo, hi;
|
m128 lo, hi;
|
||||||
ue2::CharReach chars;
|
ue2::CharReach chars;
|
||||||
chars.set('a');
|
chars.set('a');
|
||||||
truffleBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
|
truffleBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
|
||||||
u8 *kt1 = new u8[size];
|
u8 *kt1 = new u8[size];
|
||||||
memset(kt1,'b',size);
|
memset(kt1,'b',size);
|
||||||
long double total_sec = 0;
|
double total_sec = 0.0;
|
||||||
long double trans_size = 0;
|
u64a transferred_size = 0;
|
||||||
long double bw = 0;
|
double bandwitdh = 0.0;
|
||||||
if (has_match){
|
double max_bw = 0.0;
|
||||||
|
double avg_time = 0.0;
|
||||||
|
if (has_match) {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for(int j=0; j<M; j++){
|
for(int j = 0; j < M; j++) {
|
||||||
kt1[pos] = 'b';
|
kt1[pos] = 'b';
|
||||||
srand (time(NULL));
|
srand (time(NULL));
|
||||||
pos = rand() % size + 0;
|
pos = rand() % size + 0;
|
||||||
kt1[pos] = 'a';
|
kt1[pos] = 'a';
|
||||||
unsigned long act_size = 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;
|
||||||
|
}
|
||||||
|
auto end = std::chrono::steady_clock::now();
|
||||||
|
double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||||
|
total_sec += dt;
|
||||||
|
/*convert microseconds to seconds*/
|
||||||
|
total_sec /= 1000000.0;
|
||||||
|
/*calculate bandwidth*/
|
||||||
|
bandwitdh += act_size / total_sec;
|
||||||
|
/*convert to MB/s*/
|
||||||
|
bandwitdh = bandwitdh / 1048576.0;
|
||||||
|
max_bw = std::max(bandwitdh ,max_bw);
|
||||||
|
/*calculate average time*/
|
||||||
|
avg_time += total_sec / loops;
|
||||||
|
}
|
||||||
|
avg_time /= M;
|
||||||
|
bandwitdh /= M;
|
||||||
|
/*convert average time to us*/
|
||||||
|
avg_time *= 1000000.0;
|
||||||
|
printf(KMAG "TruffleExec: case with %u matches, %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",
|
||||||
|
M, size ,loops, total_sec, avg_time, max_bw, bandwitdh);
|
||||||
|
} else {
|
||||||
auto start = std::chrono::steady_clock::now();
|
auto start = std::chrono::steady_clock::now();
|
||||||
for (int i = 0; i < loops; i++) {
|
for (int i = 0; i < loops; i++) {
|
||||||
|
truffleExec(lo, hi, kt1, kt1 + size);
|
||||||
|
}
|
||||||
|
auto end = std::chrono::steady_clock::now();
|
||||||
|
total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||||
|
/*calculate transferred size*/
|
||||||
|
transferred_size = size * loops;
|
||||||
|
/*calculate average time*/
|
||||||
|
avg_time = total_sec / loops;
|
||||||
|
/*convert microseconds to seconds*/
|
||||||
|
total_sec /= 1000000.0;
|
||||||
|
/*calculate maximum bandwidth*/
|
||||||
|
max_bw = transferred_size / total_sec;
|
||||||
|
/*convert to MB/s*/
|
||||||
|
max_bw /=1048576.0;
|
||||||
|
/*calculate average bandwidth*/
|
||||||
|
bandwitdh = max_bw / loops;
|
||||||
|
printf(KMAG "TruffleExec case without matches, %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",
|
||||||
|
size ,loops, total_sec, avg_time, max_bw, bandwitdh);
|
||||||
|
}
|
||||||
|
delete [] kt1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void rtruffle_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);
|
||||||
|
double total_sec = 0.0;
|
||||||
|
u64a transferred_size = 0;
|
||||||
|
double bandwitdh = 0.0;
|
||||||
|
double max_bw = 0.0;
|
||||||
|
double avg_time = 0.0;
|
||||||
|
if (has_match) {
|
||||||
|
int pos = 0;
|
||||||
|
for(int j = 0; j < M; j++) {
|
||||||
|
kt1[pos] = 'b';
|
||||||
|
srand (time(NULL));
|
||||||
|
pos = rand() % size + 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 = rtruffleExec(lo, hi, kt1, kt1 + size);
|
const u8 *res = rtruffleExec(lo, hi, kt1, kt1 + size);
|
||||||
act_size += res - kt1;
|
act_size += res - kt1;
|
||||||
}
|
}
|
||||||
auto end = std::chrono::steady_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
long double dt = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||||
total_sec += dt;
|
total_sec += dt;
|
||||||
/*calculate transferred size*/
|
/*convert microseconds to seconds*/
|
||||||
trans_size += act_size * loops;
|
total_sec /= 1000000.0;
|
||||||
/*calculate bandwidth*/
|
/*calculate bandwidth*/
|
||||||
bw += trans_size / total_sec;
|
bandwitdh += act_size / total_sec;
|
||||||
/*convert to MB/s*/
|
/*convert to MB/s*/
|
||||||
bw += bw / 1048576;
|
bandwitdh = bandwitdh / 1048576.0;
|
||||||
/*calculte average time*/
|
max_bw = std::max(bandwitdh ,max_bw);
|
||||||
total_sec /= loops;
|
/*calculate average time*/
|
||||||
|
avg_time += total_sec / loops;
|
||||||
}
|
}
|
||||||
total_sec /= M;
|
avg_time /= M;
|
||||||
bw /= M;
|
bandwitdh /= M;
|
||||||
/*covert average time to μs*/
|
/*convert average time to us*/
|
||||||
long double ms = total_sec * 1000000;
|
avg_time *= 1000000.0;
|
||||||
std::cout<<"\x1B[35m Case with match in random pos and size: "<< real_size <<" for "<<loops<<" loops ("
|
printf(KMAG "rTruffleExec: case with %u matches, %u * %u iterations," KBLU " total elapsed time =" RST " %.3f s, "
|
||||||
<< M <<" random possisions checked):"<<"\x1B[36m rtruffleExec elapsetime: \x1B[0m"
|
KBLU "average time per call =" RST " %.3f μs," KBLU " bandwidth = " RST " %.3f MB/s," KBLU " average bandwidth =" RST " %.3f MB/s \n",
|
||||||
<< (ms/M) <<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<"(ΜΒ/μs)"<<std::endl;
|
M, size ,loops, total_sec, avg_time, max_bw, bandwitdh);
|
||||||
} else {
|
} else {
|
||||||
auto start = std::chrono::steady_clock::now();
|
auto start = std::chrono::steady_clock::now();
|
||||||
for (int i = 0; i < loops; i++) {
|
for (int i = 0; i < loops; i++) {
|
||||||
rtruffleExec(lo, hi, kt1, kt1 + size);
|
rtruffleExec(lo, hi, kt1, kt1 + size);
|
||||||
}
|
}
|
||||||
auto end = std::chrono::steady_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
total_sec += std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||||
/*calculate transferred size*/
|
/*calculate transferred size*/
|
||||||
trans_size = size * loops ;
|
transferred_size = size * loops;
|
||||||
/*calculate bandwidth*/
|
/*calculate average time*/
|
||||||
bw = trans_size / total_sec;
|
avg_time = total_sec / loops;
|
||||||
|
/*convert microseconds to seconds*/
|
||||||
|
total_sec /= 1000000.0;
|
||||||
|
/*calculate maximum bandwidth*/
|
||||||
|
max_bw = transferred_size / total_sec;
|
||||||
/*convert to MB/s*/
|
/*convert to MB/s*/
|
||||||
bw /=1048576;
|
max_bw /=1048576.0;
|
||||||
/*covert average time to μs*/
|
/*calculate average bandwidth*/
|
||||||
long double ms = total_sec * 1000000;
|
bandwitdh = max_bw / loops;
|
||||||
std::cout<<"\x1B[35m Case with no match in random pos and size: "<<real_size<<" for "<<loops<<" loops:"
|
printf(KMAG "rTruffleExec case without matches, %u * %u iterations," KBLU " total elapsed time =" RST " %.3f s, "
|
||||||
<<"\x1B[36m rtruffleExec elapsetime: \x1B[0m"<<(ms/loops)<<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/s)"<<std::endl;
|
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;
|
delete [] kt1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user