raw pointers replaced with smart pointers

This commit is contained in:
apostolos
2021-09-15 13:03:25 +03:00
committed by Konstantinos Margaritis
parent d9b8e9e224
commit 390573a07a
4 changed files with 33 additions and 35 deletions

View File

@@ -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;
}