mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-11-16 01:12:15 +03:00
benchmarks output fixes
This commit is contained in:
committed by
Konstantinos Margaritis
parent
98a950f405
commit
d1cf8989c7
@@ -1,9 +1,11 @@
|
||||
#include "nfa/shufti.h"
|
||||
#include "nfa/shufticompile.h"
|
||||
#include "benchmarks.hpp"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <cstdlib>
|
||||
|
||||
/*
|
||||
#define RST "\x1B[0m"
|
||||
@@ -19,9 +21,13 @@
|
||||
|
||||
void shufti_benchmarks(int size, int loops, int M, bool has_match) {
|
||||
m128 lo, hi;
|
||||
char *kt1 = new char[size];
|
||||
ue2::CharReach chars;
|
||||
chars.set('a');
|
||||
int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
|
||||
u8 *kt1 = new u8[size];
|
||||
memset(kt1,'b',size);
|
||||
double total_sec = 0;
|
||||
double bw = 0;
|
||||
if (has_match){
|
||||
int pos = 0;
|
||||
for(int j=0; j<M; j++){
|
||||
@@ -29,34 +35,55 @@ void shufti_benchmarks(int size, int loops, int M, bool has_match) {
|
||||
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/M; i++) {
|
||||
shuftiExec(lo, hi, (u8 *)kt1 + i, (u8 *)kt1 + strlen(kt1));
|
||||
for (int i = 0; i < loops; i++) {
|
||||
const u8 *res = shuftiExec(lo, hi, kt1, kt1 + size);
|
||||
act_size += res - kt1;
|
||||
}
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
std::chrono::duration<double> shuftiExec_elapsed_seconds = end-start;
|
||||
total_sec += shuftiExec_elapsed_seconds.count();
|
||||
double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||
/*average time*/
|
||||
dt /= loops;
|
||||
total_sec += dt;
|
||||
/*average size*/
|
||||
act_size /= loops;
|
||||
double mb_size = (double) act_size / 1048576;
|
||||
bw += mb_size / dt;
|
||||
}
|
||||
total_sec /= M;
|
||||
std::cout<<"\x1B[35m Case with match in random pos and size: "<<size<<" for "<<loops<<" loops ("<< M <<" random possisions checked):"<<"\x1B[36m shuftiExec elapsetime: \x1B[0m"<<total_sec<<"\x1B[36m bandwidth: \x1B[0m"<<(size/total_sec)<<std::endl;
|
||||
bw /= M;
|
||||
std::cout << "\x1B[35m Case with match in random pos and size: " << 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)"<<std::endl;
|
||||
} else {
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
for (int i = 0; i < loops; i++) {
|
||||
shuftiExec(lo, hi, (u8 *)kt1 + i, (u8 *)kt1 + strlen(kt1));
|
||||
shuftiExec(lo, hi, kt1, kt1 + size);
|
||||
}
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
std::chrono::duration<double> shuftiExec_elapsed_seconds = end-start;
|
||||
total_sec += shuftiExec_elapsed_seconds.count();
|
||||
std::cout<<"\x1B[35m Case with no match in random pos and size: "<<size<<" for "<<loops<<" loops:"<<"\x1B[36m shuftiExec elapsetime: \x1B[0m"<<total_sec<<"\x1B[36m bandwidth: \x1B[0m"<<(size/total_sec)<<std::endl;
|
||||
total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||
/*average time*/
|
||||
total_sec /= loops;
|
||||
double mb_size = (double) size / 1048576;
|
||||
/*average size*/
|
||||
mb_size /= loops;
|
||||
bw = mb_size / total_sec;
|
||||
std::cout<<"\x1B[35m Case with no match in random pos and size: "<<size<<" for "<<loops<<" loops:"
|
||||
<<"\x1B[36m shuftiExec elapsetime: \x1B[0m"<<(total_sec)<<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/μs)"<<std::endl;
|
||||
}
|
||||
delete [] kt1;
|
||||
}
|
||||
|
||||
void rshufti_benchmarks(int size, int loops, int M, bool has_match) {
|
||||
m128 lo, hi;
|
||||
char *kt1 = new char[size];
|
||||
ue2::CharReach chars;
|
||||
chars.set('a');
|
||||
int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
|
||||
u8 *kt1 = new u8[size];
|
||||
memset(kt1,'b',size);
|
||||
double total_sec = 0;
|
||||
long double bw = 0;
|
||||
if (has_match){
|
||||
int pos = 0;
|
||||
for(int j=0; j<M; j++){
|
||||
@@ -64,25 +91,42 @@ void rshufti_benchmarks(int size, int loops, int M, bool has_match) {
|
||||
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/M; i++) {
|
||||
rshuftiExec(lo, hi, (u8 *)kt1 + i, (u8 *)kt1 + strlen(kt1));
|
||||
for (int i = 0; i < loops; i++) {
|
||||
const u8 *res = rshuftiExec(lo, hi, kt1, kt1 + size);
|
||||
act_size += res - kt1;
|
||||
}
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
std::chrono::duration<double> shuftiExec_elapsed_seconds = end-start;
|
||||
total_sec += shuftiExec_elapsed_seconds.count();
|
||||
double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||
/*average time*/
|
||||
dt /= loops;
|
||||
total_sec += dt;
|
||||
/*average size*/
|
||||
act_size /= loops;
|
||||
double mb_size = (double) act_size / 1048576;
|
||||
bw += mb_size / dt;
|
||||
}
|
||||
total_sec /= M;
|
||||
std::cout<<"\x1B[35m Case with match in random pos and size: "<<size<<" for "<<loops<<" loops ("<< M <<" random possisions checked):"<<"\x1B[36m rshuftiExec elapsetime: \x1B[0m"<<total_sec<<"\x1B[36m bandwidth: \x1B[0m"<<(size/total_sec)<<std::endl;
|
||||
bw /= M;
|
||||
std::cout << "\x1B[35m Case with match in random pos and size: " << 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)"<<std::endl;
|
||||
} else {
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
for (int i = 0; i < loops; i++) {
|
||||
rshuftiExec(lo, hi, (u8 *)kt1 + i, (u8 *)kt1 + strlen(kt1));
|
||||
rshuftiExec(lo, hi, kt1, kt1 + size);
|
||||
}
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
std::chrono::duration<double> shuftiExec_elapsed_seconds = end-start;
|
||||
total_sec += shuftiExec_elapsed_seconds.count();
|
||||
std::cout<<"\x1B[35m Case with no match in random pos and size: "<<size<<" for "<<loops<<" loops:"<<"\x1B[36m rshuftiExec elapsetime: \x1B[0m"<<total_sec<<"\x1B[36m bandwidth: \x1B[0m"<<(size/total_sec)<<std::endl;
|
||||
total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||
/*average time*/
|
||||
total_sec /=loops;
|
||||
double mb_size = (double) size / 1048576;
|
||||
/*average size*/
|
||||
mb_size /=loops;
|
||||
bw = mb_size / total_sec;
|
||||
std::cout<<"\x1B[35m Case with no match in random pos and size: "<< size <<" for "<< loops <<" loops:"
|
||||
<<"\x1B[36m rshuftiExec elapsetime: \x1B[0m"<< total_sec <<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/μs)"<<std::endl;
|
||||
}
|
||||
delete [] kt1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user