diff --git a/CMakeLists.txt b/CMakeLists.txt index b9d8f725..2b999a00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1400,3 +1400,8 @@ option(BUILD_EXAMPLES "Build Hyperscan example code (default TRUE)" TRUE) if(BUILD_EXAMPLES) add_subdirectory(examples) endif() + +option(BUILD_BENCHMARKS "Build benchmarks (default TRUE)" TRUE) +if(BUILD_BENCHMARKS) + add_subdirectory(benchmarks) +endif() diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt new file mode 100644 index 00000000..debfc0ca --- /dev/null +++ b/benchmarks/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(benchmarks benchmarks.cpp shufti.cpp truffle.cpp noodle.cpp) +set_source_files_properties(shufti.cpp PROPERTIES COMPILE_FLAGS + "-Wall -Wno-unused-variable") +target_link_libraries(benchmarks hs) \ No newline at end of file diff --git a/benchmarks/benchmarks.cpp b/benchmarks/benchmarks.cpp new file mode 100644 index 00000000..8354a2d4 --- /dev/null +++ b/benchmarks/benchmarks.cpp @@ -0,0 +1,119 @@ +#include "benchmarks.hpp" +#include +#include +#include +#include +int main(){ + int sizes[]= { 10000, 16000, 32000, 64000, 120000, 1232896, 1600000, 2000000, 2500000, 3500000, 100000000, 150000000, 250000000, 350000000, 500000000}; + int iters[]= { 10000, 16000, 32000, 64000, 120000, 5000, 3000, 3000, 3000, 2000, 25, 25, 3, 3, 2}; + int exp_len[]= { 10000, 16000, 32000, 64000, 120000, 600000, 1000000, 1000000, 1500000, 3500000, 1000000, 10000000, 20000000, 30000000, 40000000}; + const char charset[] = "aAaAaAaAAAaaaaAAAAaaaaAAAAAAaaaAAaaa"; + std::cout< kill + noodle_benchmarks(2500000, 5000, "AaAAaaaA", 8, 1); ---> kill + γενικά όταν βάζω ένα string μεγέθους > 4 για nocase = 1 κάνει kill. + */ + std::cout< +#include "ue2common.h" +#include "benchmarks.hpp" +#include "hwlm/noodle_build.h" +#include "hwlm/noodle_engine.h" +#include "hwlm/hwlm.h" +#include "hwlm/hwlm_literal.h" +#include "scratch.h" +#include +#include + + +struct hlmMatchEntry { + size_t to; + u32 id; + hlmMatchEntry(size_t end, u32 identifier) : + to(end), id(identifier) {} +}; + +std::vector ctxt; + +static +hwlmcb_rv_t hlmSimpleCallback(size_t to, u32 id, + UNUSED struct hs_scratch *scratch) { + DEBUG_PRINTF("match @%zu = %u\n", to, id); + + ctxt.push_back(hlmMatchEntry(to, id)); + + return HWLM_CONTINUE_MATCHING; +} + +void noodle_benchmarks(int size, int M, const char *lit_str, int lit_len, char nocase){ + ctxt.clear(); + u8 *data = new u8[size]; + memset(data, 'a', size); + double total_sec = 0; + u32 id = 1000; + ue2::hwlmLiteral lit(std::string(lit_str, lit_len), nocase, id); + auto n = ue2::noodBuildTable(lit); + assert(n != nullptr); + struct hs_scratch scratch; + for (int i = 0; i < M; i++){ + auto start = std::chrono::steady_clock::now(); + noodExec(n.get(), data, size, 0, hlmSimpleCallback, &scratch); + auto end = std::chrono::steady_clock::now(); + std::chrono::duration noodExec_elapsed_seconds = end-start; + total_sec += noodExec_elapsed_seconds.count(); + } + total_sec /= M; + std::cout<<"\x1B[35m Case with match in random pos and size: "< +#include +#include +/* +#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) { + m128 lo, hi; + char *kt1 = new char[size]; + memset(kt1,'b',size); + double total_sec = 0; + if (has_match){ + int pos = 0; + for(int j=0; j shuftiExec_elapsed_seconds = end-start; + total_sec += shuftiExec_elapsed_seconds.count(); + } + total_sec /= M; + std::cout<<"\x1B[35m Case with match in random pos and size: "< shuftiExec_elapsed_seconds = end-start; + total_sec += shuftiExec_elapsed_seconds.count(); + std::cout<<"\x1B[35m Case with no match in random pos and size: "< shuftiExec_elapsed_seconds = end-start; + total_sec += shuftiExec_elapsed_seconds.count(); + } + total_sec /= M; + std::cout<<"\x1B[35m Case with match in random pos and size: "< shuftiExec_elapsed_seconds = end-start; + total_sec += shuftiExec_elapsed_seconds.count(); + std::cout<<"\x1B[35m Case with no match in random pos and size: "< +#include +#include +/* +#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) { + m128 lo, hi; + char *kt1 = new char[size]; + memset(kt1,'b',size); + double total_sec = 0; + if (has_match){ + int pos = 0; + for(int j=0; j shuftiExec_elapsed_seconds = end-start; + total_sec += shuftiExec_elapsed_seconds.count(); + } + total_sec /= M; + std::cout<<"\x1B[35m Case with match in random pos and size: "< shuftiExec_elapsed_seconds = end-start; + total_sec += shuftiExec_elapsed_seconds.count(); + std::cout<<"\x1B[35m Case with no match in random pos and size: "< shuftiExec_elapsed_seconds = end-start; + total_sec += shuftiExec_elapsed_seconds.count(); + } + total_sec /= M; + std::cout<<"\x1B[35m Case with match in random pos and size: "< shuftiExec_elapsed_seconds = end-start; + total_sec += shuftiExec_elapsed_seconds.count(); + std::cout<<"\x1B[35m Case with no match in random pos and size: "<= l; --i) { \ buf[i] = vec[i-l]; \ } \ @@ -317,7 +317,7 @@ TEST(SuperVectorUtilsTest,LShift128_128c){ /*Define RSHIFT128_128 macro*/ #define TEST_RSHIFT128_128(buf, vec, v, l) { \ - auto v_shifted = SP.rshift128(l); \ + auto v_shifted = v.rshift128(l); \ for (int i=0; i<16-l; i++) { \ buf[i] = vec[i+l]; \ } \ @@ -966,7 +966,7 @@ TEST(SuperVectorUtilsTest,RShift512c){ /*Define RSHIFT128_512 macro*/ #define TEST_RSHIFT128_512(buf, vec, v, l) { \ - auto v_shifted = SP.rshift128(l); \ + auto v_shifted = v.rshift128(l); \ for (int i=0; i<16-l; i++) { \ buf[i] = vec[i+l]; \ buf[i+16] = vec[(i+16)+l]; \