]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
bandwidth output fixes
authorapostolos <apostolos.tapsas@vectorcamp.gr>
Mon, 13 Sep 2021 17:25:46 +0000 (20:25 +0300)
committerKonstantinos Margaritis <konstantinos@vectorcamp.gr>
Tue, 12 Oct 2021 08:51:34 +0000 (11:51 +0300)
benchmarks/benchmarks.cpp
benchmarks/noodle.cpp
benchmarks/shufti.cpp
benchmarks/truffle.cpp

index 4b9610137855074a6c7d340379fc97ba9cb55e3f..e391dfcfa1174740c825e34542e6c1bdc2ada9b6 100644 (file)
@@ -6,23 +6,26 @@
 #include <functional>
 
 int main(){
-    int sizes[]=   { 16000, 32000, 64000, 120000, 1600000, 2000000, 2500000, 3500000, 150000000, 250000000, 350000000, 500000000};
-    int loops[]=   {  6000,  6000,  6000,   6000,    1000,    1000,    1000,    1000,        50,        50,        25,        25};
-    int exp_len[]= {  2000,  2000,  2000,   2000,     250,     250,     250,     250,        10,        10,         5,         5};
+    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 shuftiExec Benchmarks(kbytes)  \x1B[0m\n", "\x1B[33m rshuftiExec Benchmarks(kbytes)  \x1B[0m\n",
-                            "\x1B[33m truffleExec Benchmarks(kbytes) \x1B[0m\n", "\x1B[33m rtruffleExec Benchmarks(kbytes) \x1B[0m\n", 
-                            "\x1B[33m shuftiExec Benchmarks(Mbytes)  \x1B[0m\n", "\x1B[33m rhuftiExec Benchmarks(Mbytes)   \x1B[0m\n",
-                            "\x1B[33m truffleExec Benchmarks(Mbytes) \x1B[0m\n", "\x1B[33m rtruffleExec Benchmarks(Mbytes) \x1B[0m\n",
-                            "\x1B[33m shuftiExec Benchmarks(Gbytes)  \x1B[0m\n", "\x1B[33m rhuftiExec Benchmarks(Gbytes)   \x1B[0m\n",
-                            "\x1B[33m truffleExec Benchmarks(Gbytes) \x1B[0m\n", "\x1B[33m rtruffleExec Benchmarks(Gbytes) \x1B[0m\n"
+    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 };
-    for (int i=0; i<12; i++) {
+    for (int i=11; i<12; i++) {
         std::cout << labels[i];
         for(int j=0; j<4; j++){
-            functions[j](sizes[i],loops[i],exp_len[i],false);
-            functions[j](sizes[i],loops[i],exp_len[i],true);  
+            functions[j](sizes[i],f_loops[i],exp_len[i],false);
+            functions[j](sizes[i],t_loops[i],exp_len[i],true);  
         } 
     }
     for(int i=0; i<12; i++){
@@ -43,7 +46,7 @@ int main(){
                 str[char_len] = charset[key];
                 str[char_len + 1] = '\0';
             }
-            noodle_benchmarks(sizes[i], loops[i], str,char_len,0);
+            noodle_benchmarks(sizes[i], nd_loops[i], str,char_len,0);
             delete [] str;    
         }
     }
index 3ac37ffa349db30488fe2c3d1b87bd429ed39417..a910e0cf1466d7afafef8636d257ee3677f5e712 100644 (file)
@@ -33,7 +33,8 @@ void noodle_benchmarks(int size, int M, const char *lit_str, int lit_len, char n
     ctxt.clear();
     u8 *data = new u8[size];
     memset(data, 'a', size);
-    double total_sec = 0;
+    long double total_sec = 0;
+    long double trans_size = 0;
     long double bw = 0;
     u32 id = 1000;
     ue2::hwlmLiteral lit(std::string(lit_str, lit_len), nocase, id);
@@ -45,12 +46,16 @@ void noodle_benchmarks(int size, int M, const char *lit_str, int lit_len, char n
         noodExec(n.get(), data, size, 0, hlmSimpleCallback, &scratch); 
     }
     auto end = std::chrono::steady_clock::now();
-    total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
-    /*average time*/
-    total_sec /= M;
-    double mb_size = (double) size / 1048576;
-    bw = mb_size / total_sec;
+    total_sec += std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
+    /*calculate transferred size*/
+    trans_size = size * M;
+    /*convert to sec*/
+    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 match in random pos and size: "<< size <<" lit_len: "<< lit_len <<" nocase: "<< (int)nocase
-              << "\x1B[36m noodExec elapsetime: \x1B[0m" << total_sec << " (μs) \x1B[36m bandwidth: \x1B[0m" << bw <<" (MB/μs)" << std::endl;    
+              << "\x1B[36m noodExec elapsetime: \x1B[0m" << (ms/M) << " (μs) \x1B[36m bandwidth: \x1B[0m" << bw <<" (MB/s)" << std::endl;    
     delete [] data;
 }
\ No newline at end of file
index 934f485dcb70d1114554550490e0726714faa38a..ce576a0f92edef26a8e708c055ac58f67fea6422 100644 (file)
@@ -27,8 +27,9 @@ void shufti_benchmarks(int size, int loops, int M, bool has_match) {
     int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
     u8 *kt1 = new u8[size];
     memset(kt1,'b',size);
-    double total_sec = 0;
-    double bw = 0;
+    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++){
@@ -43,34 +44,41 @@ void shufti_benchmarks(int size, int loops, int M, bool has_match) {
                 act_size += res - kt1;
             }
             auto end = std::chrono::steady_clock::now();
-            double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
-            /*average time*/
-            dt /= loops;
+            long double dt = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
             total_sec += dt;
-            /*average size*/
-            act_size /= loops;
-            double mb_size = (double) act_size / 1048576;
-            bw += mb_size / 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;
-        std::cout << "\x1B[35m Case with match in random pos and size: " << real_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;
+        /*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 shuftiExec 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++) {
             shuftiExec(lo, hi, kt1, kt1 + size);
         }
         auto end = std::chrono::steady_clock::now();
-        total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
-        /*average time*/
-        total_sec /= loops;
-        double mb_size = (double) size / 1048576;
-        mb_size /= loops;
-        bw = mb_size / total_sec;
+        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 shuftiExec elapsetime: \x1B[0m"<<(total_sec)<<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/μs)"<<std::endl;
+                 <<"\x1B[36m shuftiExec elapsetime: \x1B[0m"<<(ms/loops)<<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/s)"<<std::endl;
     }
     delete [] kt1;
 }
@@ -83,7 +91,8 @@ void rshufti_benchmarks(int size, int loops, int M, bool has_match) {
     int ret = shuftiBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
     u8 *kt1 = new u8[size];
     memset(kt1,'b',size);
-    double total_sec = 0;
+    long double total_sec = 0;
+    long double trans_size = 0;
     long double bw = 0;
     if (has_match){
         int pos = 0;
@@ -99,33 +108,41 @@ void rshufti_benchmarks(int size, int loops, int M, bool has_match) {
                 act_size += res - kt1; 
             }
             auto end = std::chrono::steady_clock::now();
-            double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
-            /*average time*/
-            dt /= loops;
+            long double dt = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
             total_sec += dt;
-            /*average size*/
-            act_size /= loops;
-            double mb_size = (double) act_size / 1048576;
-            bw += mb_size / 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 rshuftiExec elapsetime: \x1B[0m" << total_sec
-                  <<" (μs) \x1B[36m bandwidth: \x1B[0m" << bw <<" (MB/μs)"<<std::endl;
+                  << M << " random possisions checked): \x1B[36m rshuftiExec 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++) {
             rshuftiExec(lo, hi, kt1, kt1 + size);
         }
         auto end = std::chrono::steady_clock::now();
-        total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
-        /*average time*/
-        total_sec /=loops;
-        double mb_size = (double) size / 1048576;
-        bw = mb_size / total_sec;
-        std::cout<<"\x1B[35m Case with no match in random pos and size: "<< real_size <<" for "<< loops <<" loops:"
-                 <<"\x1B[36m rshuftiExec elapsetime: \x1B[0m"<< total_sec <<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/μs)"<<std::endl;
+        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 rshuftiExec elapsetime: \x1B[0m"<<(ms/loops)<<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/s)"<<std::endl;
     }
     delete [] kt1;
 }
index b50cf6df01663e2535dbb14157a55d5b4d739ec8..0050e8d87c0ecca8620c096f8fc81a0726459091 100644 (file)
@@ -26,7 +26,8 @@ void truffle_benchmarks(int size, int loops, int M, bool has_match) {
     truffleBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
     u8*kt1 = new u8[size];
     memset(kt1,'b',size);
-    double total_sec = 0;
+    long double total_sec = 0;
+    long double trans_size = 0;
     long double bw = 0;
     if (has_match){
         int pos = 0;
@@ -42,19 +43,23 @@ void truffle_benchmarks(int size, int loops, int M, bool has_match) {
                 act_size += res - kt1;
             }
             auto end = std::chrono::steady_clock::now();
-            double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
-            /*average time*/
-            dt /= loops;
+            long double dt = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
             total_sec += dt;
-            /*average size*/
-            act_size /= loops;
-            double mb_size = (double) act_size / 1048576;
-            bw += mb_size / 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" << total_sec 
+                  << 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();
@@ -62,13 +67,17 @@ void truffle_benchmarks(int size, int loops, int M, bool has_match) {
             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();
-        /*average time*/
-        total_sec /= loops;
-        double mb_size = (double) size / 1048576;
-        bw = mb_size / total_sec;
-        std::cout<<"\x1B[35m Case with no match in random pos and size: "<< real_size <<" for "<< loops <<" loops:"
-                 <<"\x1B[36m truffleExec elapsetime: \x1B[0m" << total_sec << " μs \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/μs)"<<std::endl;
+        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;
 }
@@ -82,7 +91,8 @@ void rtruffle_benchmarks(int size, int loops, int M, bool has_match) {
     truffleBuildMasks(chars, (u8 *)&lo, (u8 *)&hi);
     u8 *kt1 = new u8[size];
     memset(kt1,'b',size);
-    double total_sec = 0;
+    long double total_sec = 0;
+    long double trans_size = 0;
     long double bw = 0;
     if (has_match){
         int pos = 0;
@@ -98,33 +108,41 @@ void rtruffle_benchmarks(int size, int loops, int M, bool has_match) {
                 act_size += res - kt1;
             }
             auto end = std::chrono::steady_clock::now();
-            double dt = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
-            /*average time*/
-            dt /= loops;
+            long double dt = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
             total_sec += dt;
-            /*average size*/
-            act_size /= loops;
-            double mb_size = (double) act_size / 1048576;
-            bw += mb_size / 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 rtruffleExec elapsetime: \x1B[0m" 
-                 << total_sec <<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<"(ΜΒ/μs)"<<std::endl;
+                 << (ms/M) <<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<"(ΜΒ/μs)"<<std::endl;
     } else {
         auto start = std::chrono::steady_clock::now();
         for (int i = 0; i < loops; i++) {
             rtruffleExec(lo, hi, kt1, kt1 + size);
         }
         auto end = std::chrono::steady_clock::now();
-        total_sec += std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
-        /*average time*/
-        total_sec /= loops;
-        double mb_size = (double) size / 1048576;
-        bw = mb_size / total_sec;
-        std::cout<<"\x1B[35m Case with no match in random pos and size: "<< real_size <<" for "<< loops <<" loops:"
-                 <<"\x1B[36m rtruffleExec elapsetime: \x1B[0m" << total_sec <<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/μs)"<<std::endl;
+        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 rtruffleExec elapsetime: \x1B[0m"<<(ms/loops)<<" (μs) \x1B[36m bandwidth: \x1B[0m"<< bw <<" (MB/s)"<<std::endl;
     }
     delete [] kt1;
 }