]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
code size reduction by using function arrays and add bandwidth to output
authorapostolos <apostolos.tapsas@vectorcamp.gr>
Wed, 25 Aug 2021 08:09:45 +0000 (11:09 +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 8354a2d4408dbe03efeb4b98be52e233071a5192..d2c5fa8a0e1edb16a95a4a6240c51bbb95143b28 100644 (file)
 #include <string>
 #include <string.h>
 #include <time.h>
+#include <functional>
 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};
+    int sizes[]=   { 16000, 32000, 64000, 120000, 1600000, 2000000, 2500000, 3500000, 150000000, 250000000, 350000000, 500000000};
+    int iters[]=   { 16000, 32000, 64000, 120000,    3000,    3000,    3000,    2000,        25,         3,         3,         2};
+    int exp_len[]= { 16000, 32000, 64000, 120000, 1000000, 1000000, 1500000, 3500000,  10000000,  20000000,  30000000,  40000000};
     const char charset[] = "aAaAaAaAAAaaaaAAAAaaaaAAAAAAaaaAAaaa";
-    std::cout<<std::endl <<"\x1B[33m shuftiExec Benchmarks(kbytes) \x1B[0m"<<std::endl;
-    for (int i = 0; i < 5; i++) { 
-        shufti_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        shufti_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    std::cout<<std::endl <<"\x1B[33m rshuftiExec Benchmarks(kbytes) \x1B[0m"<<std::endl;
-    for (int i = 0; i < 5; i++) { 
-        rshufti_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        rshufti_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    std::cout<<std::endl <<"\x1B[33m truffleExec Benchmarks(kbytes) \x1B[0m"<<std::endl;
-    for (int i = 0; i < 5; i++) { 
-        truffle_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        truffle_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    std::cout<<std::endl <<"\x1B[33m rtruffleExec Benchmarks(kbytes) \x1B[0m"<<std::endl;
-     for (int i = 0; i < 5; i++) { 
-        rtruffle_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        rtruffle_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    std::cout<<std::endl <<"\x1B[33m shuftiExec Benchmarks(Mbytes) \x1B[0m"<<std::endl;
-    for (int i = 5; i < 10; i++) { 
-        shufti_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        shufti_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    std::cout<<std::endl <<"\x1B[33m rshuftiExec Benchmarks(Mbytes) \x1B[0m"<<std::endl;
-    for (int i = 5; i < 10; i++) { 
-        rshufti_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        rshufti_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    std::cout<<std::endl <<"\x1B[33m truffleExec Benchmarks(Mbytes) \x1B[0m"<<std::endl;
-     for (int i = 5; i < 10; i++) { 
-        truffle_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        truffle_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    std::cout<<std::endl <<"\x1B[33m rtruffleExec Benchmarks(Mbytes) \x1B[0m"<<std::endl;
-     for (int i = 5; i < 10; i++) { 
-        rtruffle_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        rtruffle_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    std::cout<<std::endl <<"\x1B[33m shuftiExec Benchmarks(Gbytes) \x1B[0m"<<std::endl;
-    for (int i = 10; i < 15; i++) { 
-        shufti_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        shufti_benchmarks(sizes[i],iters[i],exp_len[i],true);
-        // run time 2.5 min
-    }
-    std::cout<<std::endl <<"\x1B[33m rshuftiExec Benchmarks(Gbytes) \x1B[0m"<<std::endl;
-    for (int i = 10; i < 15; i++) { 
-        rshufti_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        rshufti_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    std::cout<<std::endl <<"\x1B[33m truffleExec Benchmarks(Gbytes) \x1B[0m"<<std::endl;
-     for (int i = 10; i < 15; i++) { 
-        truffle_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        truffle_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    std::cout<<std::endl <<"\x1B[33m rtruffleExec Benchmarks(Gbytes) \x1B[0m"<<std::endl;
-     for (int i = 10; i < 15; i++) { 
-        rtruffle_benchmarks(sizes[i],iters[i],exp_len[i],false);
-        rtruffle_benchmarks(sizes[i],iters[i],exp_len[i],true);
-    }
-    /*noodle_benchmarks(120000, 32000, "aaaA", 4, 1); ---> kill
-      noodle_benchmarks(2500000, 5000, "AaAAaaaA", 8, 1); ---> kill
-      γενικά όταν βάζω ένα string μεγέθους > 4 για nocase = 1 κάνει kill.
-    */
-    std::cout<<std::endl <<"\x1B[33m noodle Benchmarks(kbytes) \x1B[0m"<<std::endl;
-    for (int char_len = 1; char_len < 9; char_len++) {
-        char *str = new char[char_len];
-        for (int j=0; j<char_len; j++) {
-            srand (time(NULL));
-            int key = rand() % + 36 ;
-            str[char_len] = charset[key];
-            str[char_len + 1] = '\0';
-        }
-        for (int i=0; i<5; i++){
-            noodle_benchmarks(sizes[i], iters[i], str,char_len,0);
-        }
-        delete [] str;    
-    }
-    std::cout<<std::endl <<"\x1B[33m noodle Benchmarks(Mbytes) \x1B[0m"<<std::endl;
-    for (int char_len = 1; char_len < 9; char_len++) {
-        char *str = new char[char_len];
-        for (int j=0; j<char_len; j++) {
-            srand (time(NULL));
-            int key = rand() % + 36 ;
-            str[char_len] = charset[key];
-            str[char_len + 1] = '\0';
-        }
-        for (int i=5; i<10; i++){
-            noodle_benchmarks(sizes[i], iters[i], str,char_len,0);
-        }
-        delete [] str;    
-    }
-    std::cout<<std::endl <<"\x1B[33m noodle Benchmarks(Gbytes) \x1B[0m"<<std::endl;
-    for (int char_len = 1; char_len < 9; char_len++) {
-        char *str = new char[char_len];
-        for (int j=0; j<char_len; j++) {
-            srand (time(NULL));
-            int key = rand() % + 36 ;
-            str[char_len] = charset[key];
-            str[char_len + 1] = '\0';
+    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::function<void(int,int,int,bool)>  functions[] = { shufti_benchmarks, rshufti_benchmarks, truffle_benchmarks, rtruffle_benchmarks };
+    
+    for (int i=0; i<12; i++) {
+        std::cout << labels[i];
+        for(int j=0; j<4; j++){
+            functions[j](sizes[i],iters[i],exp_len[i],false);
+            functions[j](sizes[i],iters[i],exp_len[i],true);  
+        } 
+    }
+
+    for(int i=0; i<12; i++){
+        if(i==0){
+            std::cout<<std::endl <<"\x1B[33m noodle Benchmarks(kbytes) \x1B[0m"<<std::endl;
+        }else if (i==4)
+        {
+            std::cout<<std::endl <<"\x1B[33m noodle Benchmarks(Mbytes) \x1B[0m"<<std::endl;
+        }else if (i==8)
+        {
+            std::cout<<std::endl <<"\x1B[33m noodle Benchmarks(Gbytes) \x1B[0m"<<std::endl;
         }
-        for (int i=10; i<15; i++){
+        for (int char_len = 1; char_len < 9; char_len++) {
+            char *str = new char[char_len];
+            for (int j=0; j<char_len; j++) {
+                srand (time(NULL));
+                int key = rand() % + 36 ;
+                str[char_len] = charset[key];
+                str[char_len + 1] = '\0';
+            }
             noodle_benchmarks(sizes[i], iters[i], str,char_len,0);
+            delete [] str;    
         }
-        delete [] str;    
     }
     return 0;
 }
\ No newline at end of file
index 3e6e2d9e355423fe38aa02c272304ec9ae684555..a710b43d7664d287e42fb70950ce6f232b81b45c 100644 (file)
@@ -47,5 +47,6 @@ void noodle_benchmarks(int size, int M, const char *lit_str, int lit_len, char n
         total_sec += noodExec_elapsed_seconds.count();
     }
     total_sec /= M;
-    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<<std::endl;    
+    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<<" bandwidth"<<(size/total_sec)<<std::endl;    
+    delete [] data;
 }
\ No newline at end of file
index 4d214e36b25ecfa4e32de04772c787b26a3d162e..b20c4f9d3742eadc70f993414323441dce3f6837 100644 (file)
@@ -36,7 +36,7 @@ void shufti_benchmarks(int size, int loops, int M, bool has_match) {
             total_sec += shuftiExec_elapsed_seconds.count();
         }
         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<<std::endl;
+        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<<" bandwidth"<<(size/total_sec)<<std::endl;
     } else {
         auto start = std::chrono::steady_clock::now();
         for (int i = 0; i < loops; i++) {
@@ -45,7 +45,7 @@ void shufti_benchmarks(int size, int loops, int M, bool has_match) {
         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<<std::endl;
+        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<<" bandwidth"<<(size/total_sec)<<std::endl;
     }
     delete [] kt1;
 }
@@ -71,7 +71,7 @@ void rshufti_benchmarks(int size, int loops, int M, bool has_match) {
             total_sec += shuftiExec_elapsed_seconds.count();
         }
         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<<std::endl;
+        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<<" bandwidth"<<(size/total_sec)<<std::endl;
     } else {
         auto start = std::chrono::steady_clock::now();
         for (int i = 0; i < loops; i++) {
@@ -80,7 +80,7 @@ void rshufti_benchmarks(int size, int loops, int M, bool has_match) {
         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<<std::endl;
+        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<<" bandwidth"<<(size/total_sec)<<std::endl;
     }
     delete [] kt1;
 }
index a28b28cea280082e9c61ceb1b7989f8c31467bf6..f20dcb864ab3a45e80fdd46d2d9dd41f7de603e0 100644 (file)
@@ -36,7 +36,7 @@ void truffle_benchmarks(int size, int loops, int M, bool has_match) {
             total_sec += shuftiExec_elapsed_seconds.count();
         }
         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 truffleExec elapsetime: \x1B[0m"<<total_sec<<std::endl;
+        std::cout<<"\x1B[35m Case with match in random pos and size: "<<size<<" for "<<loops<<" loops ("<< M <<" random possisions checked):"<<"\x1B[36m truffleExec elapsetime: \x1B[0m"<<total_sec<<" bandwidth"<<(size/total_sec)<<std::endl;
     } else {
         auto start = std::chrono::steady_clock::now();
         for (int i = 0; i < loops; i++) {
@@ -45,7 +45,7 @@ void truffle_benchmarks(int size, int loops, int M, bool has_match) {
         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 truffleExec elapsetime: \x1B[0m"<<total_sec<<std::endl;
+        std::cout<<"\x1B[35m Case with no match in random pos and size: "<<size<<" for "<<loops<<" loops:"<<"\x1B[36m truffleExec elapsetime: \x1B[0m"<<total_sec<<" bandwidth"<<(size/total_sec)<<std::endl;
     }
     delete [] kt1;
 }
@@ -72,7 +72,7 @@ void rtruffle_benchmarks(int size, int loops, int M, bool has_match) {
             total_sec += shuftiExec_elapsed_seconds.count();
         }
         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 rtruffleExec elapsetime: \x1B[0m"<<total_sec<<std::endl;
+        std::cout<<"\x1B[35m Case with match in random pos and size: "<<size<<" for "<<loops<<" loops ("<< M <<" random possisions checked):"<<"\x1B[36m rtruffleExec elapsetime: \x1B[0m"<<total_sec<<" bandwidth"<<(size/total_sec)<<std::endl;
     } else {
         auto start = std::chrono::steady_clock::now();
         for (int i = 0; i < loops; i++) {
@@ -81,7 +81,7 @@ void rtruffle_benchmarks(int size, int loops, int M, bool has_match) {
         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 rtruffleExec elapsetime: \x1B[0m"<<total_sec<<std::endl;
+        std::cout<<"\x1B[35m Case with no match in random pos and size: "<<size<<" for "<<loops<<" loops:"<<"\x1B[36m rtruffleExec elapsetime: \x1B[0m"<<total_sec<<" bandwidth"<<(size/total_sec)<<std::endl;
     }
     delete [] kt1;
 }
\ No newline at end of file