Changeset: 3424f1424f82 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3424f1424f82
Added Files:
        monetdb5/extras/pyapi/Benchmarks/randomstrings.c
Modified Files:
        monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py
        monetdb5/extras/pyapi/Benchmarks/pyapi_test.sh
Branch: pyapi
Log Message:

Added C script for generating random strings for testing (because Python is too 
slow).


diffs (116 lines):

diff --git a/monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py 
b/monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py
--- a/monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py
+++ b/monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py
@@ -278,6 +278,16 @@ elif str(arguments[1]).lower() == "outpu
     cursor.execute('rollback')
 
 elif str(arguments[1]).lower() == "string_samelength" or 
str(arguments[1]).lower() == "string_extremeunicode":
+    #todo: this
+    #benchmark_dir = os.environ["PYAPI_BENCHMARKS_DIR"]
+    #os.system("gcc " + benchmark_dir + "/randomstrings.c -o randomstrings")
+
+    #def generate_strings_samelength():
+    #   file = open("result.txt", 'r')
+    #   content = file.read()
+    #   strings = content.split(' ')
+    #   result = numpy.array(strings)
+    #   return result
     if str(arguments[1]).lower() == "string_samelength":
         def generate_strings_samelength(mb, length):
             def random_string(length):
@@ -347,6 +357,7 @@ elif str(arguments[1]).lower() == "strin
     for j in range(0,len(mb)):
         size = mb[j]
         length = lens[j]
+        #os.system("./randomstrings %s %s result.txt" % (str(size), 
str(length)))
         cursor.execute('create table strings as SELECT * FROM 
generate_strings_samelength(' + str(size) + ',' + str(length) + ') with data;')
         results = []
         result_file = open(temp_file, 'w+')
diff --git a/monetdb5/extras/pyapi/Benchmarks/pyapi_test.sh 
b/monetdb5/extras/pyapi/Benchmarks/pyapi_test.sh
--- a/monetdb5/extras/pyapi/Benchmarks/pyapi_test.sh
+++ b/monetdb5/extras/pyapi/Benchmarks/pyapi_test.sh
@@ -60,10 +60,12 @@ export PYTHON_MONETDB_DIR=python-monetdb
 export 
PYTHON_MONETDB_FILE=python-monetdb-$PYTHON_MONETDB_CONNECTOR_VERSION.tar.gz
 export 
PYTHON_MONETDB_URL=https://pypi.python.org/packages/source/p/python-monetdb/$PYTHON_MONETDB_FILE
 
+# Benchmarks DIR
+export PYAPI_BENCHMARKS_DIR=$PYAPI_MONETDB_DIR/monetdb5/extras/pyapi/Benchmarks
 # Python testfile location
-export 
PYAPI_TESTFILE=$PYAPI_MONETDB_DIR/monetdb5/extras/pyapi/Benchmarks/monetdb_testing.py
+export PYAPI_TESTFILE=$PYAPI_BENCHMARKS_DIR/monetdb_testing.py
 # Graph file location
-export 
PYAPI_GRAPHFILE=$PYAPI_MONETDB_DIR/monetdb5/extras/pyapi/Benchmarks/graph.py
+export PYAPI_GRAPHFILE=$PYAPI_BENCHMARKS_DIR/graph.py
 
 # Try a bunch of popular different terminals
 export SETSID=0
diff --git a/monetdb5/extras/pyapi/Benchmarks/randomstrings.c 
b/monetdb5/extras/pyapi/Benchmarks/randomstrings.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/pyapi/Benchmarks/randomstrings.c
@@ -0,0 +1,65 @@
+
+
+// Small file for generating random strings of the same length
+// Parameters are string_size (MB), string_length (#chars), file name
+// The strings are saved in the specified file separated by spaces
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+
+
+int main(int argc, char *argv[])
+{
+       srand(377);
+
+       if (argc != 4) {
+               fprintf(stderr, "Invalid number of arguments for random 
generation, expected \"size[mb] string_length[chars] result_file[name]\"\n");
+               exit(1);
+       }
+
+       double size_mb;
+       int string_count;
+       int string_length;
+
+       size_mb = strtod(argv[1], NULL);
+       string_length = atoi(argv[2]);
+
+       string_count = (int) (size_mb * 1000 * 1000) / string_length;
+
+       char option_string[] = 
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+       size_t options = strlen(option_string);
+       const size_t rand_division = RAND_MAX / options;
+       size_t result_size = string_length * string_count + string_count - 1;
+       char *result = malloc(sizeof(char) * result_size + 1);
+       result[result_size] = '\0';
+       char sep = ' ';
+       size_t i, j;
+
+       for(i = 0; i < result_size; i += string_length + 1) {
+               for(j = 0; j < string_length; j++) {
+                       result[i + j] = option_string[rand() / rand_division];
+               }
+       }
+       for(i = string_length; i < result_size; i += string_length + 1) {
+               result[i] = sep;
+       }
+       int MAX_BUFFER_SIZE = 100000;
+       {
+               FILE *f = fopen(argv[3], "w");
+               for(i = 0; i < result_size / MAX_BUFFER_SIZE; i++) {
+                       int tempindex = (i + 1) * MAX_BUFFER_SIZE;
+                       char tmp = result[tempindex];
+                       result[tempindex] = '\0';
+                       fprintf(f, "%s", result + i * MAX_BUFFER_SIZE);
+                       result[tempindex] = tmp;
+               }
+               fprintf(f, "%s", result + i * MAX_BUFFER_SIZE);
+               fclose(f);
+       }
+
+       free(result);
+       return 0;
+}
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to