mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
changed color output to csv output
This commit is contained in:
parent
d7fb5f437a
commit
50a62a17ff
@ -26,13 +26,13 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <cstdlib>
|
|
||||||
#include <memory>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "benchmarks.hpp"
|
#include "benchmarks.hpp"
|
||||||
|
|
||||||
@ -43,14 +43,12 @@
|
|||||||
struct hlmMatchEntry {
|
struct hlmMatchEntry {
|
||||||
size_t to;
|
size_t to;
|
||||||
u32 id;
|
u32 id;
|
||||||
hlmMatchEntry(size_t end, u32 identifier) :
|
hlmMatchEntry(size_t end, u32 identifier) : to(end), id(identifier) {}
|
||||||
to(end), id(identifier) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<hlmMatchEntry> ctxt;
|
std::vector<hlmMatchEntry> ctxt;
|
||||||
|
|
||||||
static
|
static hwlmcb_rv_t hlmSimpleCallback(size_t to, u32 id,
|
||||||
hwlmcb_rv_t hlmSimpleCallback(size_t to, u32 id,
|
|
||||||
UNUSED struct hs_scratch *scratch) {
|
UNUSED struct hs_scratch *scratch) {
|
||||||
DEBUG_PRINTF("match @%zu = %u\n", to, id);
|
DEBUG_PRINTF("match @%zu = %u\n", to, id);
|
||||||
|
|
||||||
@ -60,7 +58,9 @@ hwlmcb_rv_t hlmSimpleCallback(size_t to, u32 id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename InitFunc, typename BenchFunc>
|
template <typename InitFunc, typename BenchFunc>
|
||||||
static void run_benchmarks(int size, int loops, int max_matches, bool is_reverse, MicroBenchmark &bench, InitFunc &&init, BenchFunc &&func) {
|
static void run_benchmarks(int size, int loops, int max_matches,
|
||||||
|
bool is_reverse, MicroBenchmark &bench,
|
||||||
|
InitFunc &&init, BenchFunc &&func) {
|
||||||
init(bench);
|
init(bench);
|
||||||
double total_sec = 0.0;
|
double total_sec = 0.0;
|
||||||
u64a total_size = 0;
|
u64a total_size = 0;
|
||||||
@ -84,7 +84,9 @@ static void run_benchmarks(int size, int loops, int max_matches, bool is_reverse
|
|||||||
actual_size += res - bench.buf.data();
|
actual_size += res - bench.buf.data();
|
||||||
}
|
}
|
||||||
auto end = std::chrono::steady_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
double dt = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||||
|
end - start)
|
||||||
|
.count();
|
||||||
total_sec += dt;
|
total_sec += dt;
|
||||||
/*convert microseconds to seconds*/
|
/*convert microseconds to seconds*/
|
||||||
/*calculate bandwidth*/
|
/*calculate bandwidth*/
|
||||||
@ -102,16 +104,26 @@ static void run_benchmarks(int size, int loops, int max_matches, bool is_reverse
|
|||||||
avg_bw /= max_matches;
|
avg_bw /= max_matches;
|
||||||
total_sec /= 1000000.0;
|
total_sec /= 1000000.0;
|
||||||
/*convert average time to us*/
|
/*convert average time to us*/
|
||||||
printf(KMAG "%s: %u matches, %u * %u iterations," KBLU " total elapsed time =" RST " %.3f s, "
|
/* Keeping the color output
|
||||||
KBLU "average time per call =" RST " %.3f μs," KBLU " max bandwidth = " RST " %.3f MB/s," KBLU " average bandwidth =" RST " %.3f MB/s \n",
|
printf(KMAG "%s: %u matches, %u * %u iterations," KBLU
|
||||||
bench.label, max_matches, size ,loops, total_sec, avg_time, max_bw, avg_bw);
|
" total elapsed time =" RST " %.3f s, " KBLU
|
||||||
|
"average time per call =" RST " %.3f μs," KBLU
|
||||||
|
" max bandwidth = " RST " %.3f MB/s," KBLU
|
||||||
|
" average bandwidth =" RST " %.3f MB/s \n",
|
||||||
|
bench.label, max_matches, size, loops, total_sec, avg_time,
|
||||||
|
max_bw, avg_bw);
|
||||||
|
*/
|
||||||
|
printf("%s,%u,%u,%u,%.3f,%.3f,%.3f,%.3f\n", bench.label, max_matches,
|
||||||
|
size, loops, total_sec, avg_time, max_bw, avg_bw);
|
||||||
} 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++) {
|
||||||
const u8 *res = func(bench);
|
const u8 *res = func(bench);
|
||||||
}
|
}
|
||||||
auto end = std::chrono::steady_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
total_sec +=
|
||||||
|
std::chrono::duration_cast<std::chrono::microseconds>(end - start)
|
||||||
|
.count();
|
||||||
/*calculate transferred size*/
|
/*calculate transferred size*/
|
||||||
total_size = size * loops;
|
total_size = size * loops;
|
||||||
/*calculate average time*/
|
/*calculate average time*/
|
||||||
@ -122,101 +134,114 @@ static void run_benchmarks(int size, int loops, int max_matches, bool is_reverse
|
|||||||
max_bw = total_size / total_sec;
|
max_bw = total_size / total_sec;
|
||||||
/*convert to MB/s*/
|
/*convert to MB/s*/
|
||||||
max_bw /= 1048576.0;
|
max_bw /= 1048576.0;
|
||||||
printf(KMAG "%s: no matches, %u * %u iterations," KBLU " total elapsed time =" RST " %.3f s, "
|
/*Keeping the color output
|
||||||
KBLU "average time per call =" RST " %.3f μs ," KBLU " bandwidth = " RST " %.3f MB/s \n",
|
printf(KMAG "%s: no matches, %u * %u iterations," KBLU " total elapsed
|
||||||
bench.label, size ,loops, total_sec, avg_time, max_bw );
|
time =" RST " %.3f s, " KBLU "average time per call =" RST " %.3f μs ,"
|
||||||
|
KBLU " bandwidth = " RST " %.3f MB/s \n", bench.label, size ,loops,
|
||||||
|
total_sec, avg_time, max_bw );
|
||||||
|
*/
|
||||||
|
printf("%s,0,%u,%u,%.3f,%.3f,%.3f,0\n", bench.label, size, loops,
|
||||||
|
total_sec, avg_time, max_bw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int matches[] = {0, MAX_MATCHES};
|
int matches[] = {0, MAX_MATCHES};
|
||||||
std::vector<size_t> sizes;
|
std::vector<size_t> sizes;
|
||||||
for (size_t i = 0; i < N; i++) sizes.push_back(16000 << i*2);
|
for (size_t i = 0; i < N; i++)
|
||||||
|
sizes.push_back(16000 << i * 2);
|
||||||
const char charset[] = "aAaAaAaAAAaaaaAAAAaaaaAAAAAAaaaAAaaa";
|
const char charset[] = "aAaAaAaAAAaaaaAAAAaaaaAAAAAAaaaAAaaa";
|
||||||
|
printf("Bench Label, max_matches, size,loops, total_sec, avg_time, "
|
||||||
|
"max_bw, avg_bw\n");
|
||||||
for (int m = 0; m < 2; m++) {
|
for (int m = 0; m < 2; m++) {
|
||||||
for (size_t i = 0; i < std::size(sizes); i++) {
|
for (size_t i = 0; i < std::size(sizes); i++) {
|
||||||
MicroBenchmark bench("Shufti", sizes[i]);
|
MicroBenchmark bench("Shufti", sizes[i]);
|
||||||
run_benchmarks(sizes[i], MAX_LOOPS / sizes[i], matches[m], false, bench,
|
run_benchmarks(
|
||||||
|
sizes[i], MAX_LOOPS / sizes[i], matches[m], false, bench,
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
b.chars.set('a');
|
b.chars.set('a');
|
||||||
ue2::shuftiBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
ue2::shuftiBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
||||||
memset(b.buf.data(), 'b', b.size);
|
memset(b.buf.data(), 'b', b.size);
|
||||||
},
|
},
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
return shuftiExec(b.lo, b.hi, b.buf.data(), b.buf.data() + b.size);
|
return shuftiExec(b.lo, b.hi, b.buf.data(),
|
||||||
}
|
b.buf.data() + b.size);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < std::size(sizes); i++) {
|
for (size_t i = 0; i < std::size(sizes); i++) {
|
||||||
MicroBenchmark bench("Reverse Shufti", sizes[i]);
|
MicroBenchmark bench("Reverse Shufti", sizes[i]);
|
||||||
run_benchmarks(sizes[i], MAX_LOOPS / sizes[i], matches[m], true, bench,
|
run_benchmarks(
|
||||||
|
sizes[i], MAX_LOOPS / sizes[i], matches[m], true, bench,
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
b.chars.set('a');
|
b.chars.set('a');
|
||||||
ue2::shuftiBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
ue2::shuftiBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
||||||
memset(b.buf.data(), 'b', b.size);
|
memset(b.buf.data(), 'b', b.size);
|
||||||
},
|
},
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
return rshuftiExec(b.lo, b.hi, b.buf.data(), b.buf.data() + b.size);
|
return rshuftiExec(b.lo, b.hi, b.buf.data(),
|
||||||
}
|
b.buf.data() + b.size);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < std::size(sizes); i++) {
|
for (size_t i = 0; i < std::size(sizes); i++) {
|
||||||
MicroBenchmark bench("Truffle", sizes[i]);
|
MicroBenchmark bench("Truffle", sizes[i]);
|
||||||
run_benchmarks(sizes[i], MAX_LOOPS / sizes[i], matches[m], false, bench,
|
run_benchmarks(
|
||||||
|
sizes[i], MAX_LOOPS / sizes[i], matches[m], false, bench,
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
b.chars.set('a');
|
b.chars.set('a');
|
||||||
ue2::truffleBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
ue2::truffleBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
||||||
memset(b.buf.data(), 'b', b.size);
|
memset(b.buf.data(), 'b', b.size);
|
||||||
},
|
},
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
return truffleExec(b.lo, b.hi, b.buf.data(), b.buf.data() + b.size);
|
return truffleExec(b.lo, b.hi, b.buf.data(),
|
||||||
}
|
b.buf.data() + b.size);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < std::size(sizes); i++) {
|
for (size_t i = 0; i < std::size(sizes); i++) {
|
||||||
MicroBenchmark bench("Reverse Truffle", sizes[i]);
|
MicroBenchmark bench("Reverse Truffle", sizes[i]);
|
||||||
run_benchmarks(sizes[i], MAX_LOOPS / sizes[i], matches[m], true, bench,
|
run_benchmarks(
|
||||||
|
sizes[i], MAX_LOOPS / sizes[i], matches[m], true, bench,
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
b.chars.set('a');
|
b.chars.set('a');
|
||||||
ue2::truffleBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
ue2::truffleBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
||||||
memset(b.buf.data(), 'b', b.size);
|
memset(b.buf.data(), 'b', b.size);
|
||||||
},
|
},
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
return rtruffleExec(b.lo, b.hi, b.buf.data(), b.buf.data() + b.size);
|
return rtruffleExec(b.lo, b.hi, b.buf.data(),
|
||||||
}
|
b.buf.data() + b.size);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < std::size(sizes); i++) {
|
for (size_t i = 0; i < std::size(sizes); i++) {
|
||||||
MicroBenchmark bench("Vermicelli", sizes[i]);
|
MicroBenchmark bench("Vermicelli", sizes[i]);
|
||||||
run_benchmarks(sizes[i], MAX_LOOPS / sizes[i], matches[m], false, bench,
|
run_benchmarks(
|
||||||
|
sizes[i], MAX_LOOPS / sizes[i], matches[m], false, bench,
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
b.chars.set('a');
|
b.chars.set('a');
|
||||||
ue2::truffleBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
ue2::truffleBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
||||||
memset(b.buf.data(), 'b', b.size);
|
memset(b.buf.data(), 'b', b.size);
|
||||||
},
|
},
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
return vermicelliExec('a', 'b', b.buf.data(), b.buf.data() + b.size);
|
return vermicelliExec('a', 'b', b.buf.data(),
|
||||||
}
|
b.buf.data() + b.size);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < std::size(sizes); i++) {
|
for (size_t i = 0; i < std::size(sizes); i++) {
|
||||||
MicroBenchmark bench("Reverse Vermicelli", sizes[i]);
|
MicroBenchmark bench("Reverse Vermicelli", sizes[i]);
|
||||||
run_benchmarks(sizes[i], MAX_LOOPS / sizes[i], matches[m], true, bench,
|
run_benchmarks(
|
||||||
|
sizes[i], MAX_LOOPS / sizes[i], matches[m], true, bench,
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
b.chars.set('a');
|
b.chars.set('a');
|
||||||
ue2::truffleBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
ue2::truffleBuildMasks(b.chars, (u8 *)&b.lo, (u8 *)&b.hi);
|
||||||
memset(b.buf.data(), 'b', b.size);
|
memset(b.buf.data(), 'b', b.size);
|
||||||
},
|
},
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
return rvermicelliExec('a', 'b', b.buf.data(), b.buf.data() + b.size);
|
return rvermicelliExec('a', 'b', b.buf.data(),
|
||||||
}
|
b.buf.data() + b.size);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < std::size(sizes); i++) {
|
for (size_t i = 0; i < std::size(sizes); i++) {
|
||||||
@ -232,7 +257,8 @@ int main(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
MicroBenchmark bench("Noodle", sizes[i]);
|
MicroBenchmark bench("Noodle", sizes[i]);
|
||||||
run_benchmarks(sizes[i], MAX_LOOPS / sizes[i], matches[m], false, bench,
|
run_benchmarks(
|
||||||
|
sizes[i], MAX_LOOPS / sizes[i], matches[m], false, bench,
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
ctxt.clear();
|
ctxt.clear();
|
||||||
memset(b.buf.data(), 'a', b.size);
|
memset(b.buf.data(), 'a', b.size);
|
||||||
@ -242,10 +268,10 @@ int main(){
|
|||||||
assert(b.nt != nullptr);
|
assert(b.nt != nullptr);
|
||||||
},
|
},
|
||||||
[&](MicroBenchmark &b) {
|
[&](MicroBenchmark &b) {
|
||||||
noodExec(b.nt.get(), b.buf.data(), b.size, 0, hlmSimpleCallback, &b.scratch);
|
noodExec(b.nt.get(), b.buf.data(), b.size, 0,
|
||||||
|
hlmSimpleCallback, &b.scratch);
|
||||||
return b.buf.data() + b.size;
|
return b.buf.data() + b.size;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user