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

Added psycopg2 [postgres python client], pytables and castra benchmarks.


diffs (283 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
@@ -529,6 +529,7 @@ if str(args_input_database).lower() == "
 else:
     input_file = os.environ["POSTGRES_INPUT_FILE"]
     input_dir = os.environ["POSTGRES_CWD"]
+    drop_cache = os.environ["DROP_CACHE_COMMAND"]
     def execute_test(input_type, database_init, database_load, 
database_execute, database_clear, database_final):
         database_init()
 
@@ -545,7 +546,7 @@ else:
 
             database_load()
             for i in range(0,test_count):
-                os.system('/home/mytherin/bin/flushcache')
+                #os.system(drop_cache)
                 start = time.time()
                 database_execute()
                 end = time.time()
@@ -666,16 +667,16 @@ AS $$
         import monetdb.sql
         for i in range(0, max_retries):
             try:
-                connection = monetdb.sql.connect(username="monetdb", 
password="monetdb", hostname="localhost",port=port,database="demo")
+                conn = monetdb.sql.connect(username="monetdb", 
password="monetdb", hostname="localhost",port=port,database="demo")
                 break
             except:
                 time.sleep(1)
-            connection = None
+            conn = None
 
-        if connection is None:
+        if conn is None:
             print("Failed to connect to MonetDB Server (mserver5) in " + 
str(max_retries) + " attempts.")
             sys.exit(1)
-        c = connection.cursor()
+        c = conn.cursor()
 
         def monetdb_init():
             return None
@@ -712,9 +713,75 @@ AS $$
             conn.close()
 
         execute_test(input_type, monetdb_init, monetdb_load, monetdb_execute, 
monetdb_clear, monetdb_final)
+    elif str(args_input_database).lower() == "psycopg2":
+        dbname = os.environ["POSTGRES_DB_NAME"]
+        initdb = os.environ["POSTGRES_CREATEDB_COMMAND"]
+        dropdb = os.environ["POSTGRES_DROPDB_COMMAND"]
+        os.system(initdb)
+        import psycopg2
+        conn = psycopg2.connect("dbname=%s host=/tmp/" % dbname)
+        c = conn.cursor()
+        def psycopg2_init():
+            return None
 
+        def psycopg2_load():
+            c.execute("CREATE TABLE integers(i integer);")
+            c.execute("COPY integers FROM '%s' DELIMITER ',' CSV;" % 
input_file)
+
+
+        def psycopg2_execute():
+            c.execute("SELECT * FROM integers;")
+            result = c.fetchall()
+            print function(numpy.array(result, dtype=numpy.int32))
+
+        def psycopg2_clear():
+            c.execute("DROP TABLE integers;")
+
+        def psycopg2_final():
+            os.system(dropdb)
+            conn.close()
+            os.remove(input_file)
+
+        execute_test(input_type, psycopg2_init, psycopg2_load, 
psycopg2_execute, psycopg2_clear, psycopg2_final)
     elif str(args_input_database).lower() == "pytables":
-        print("Not implemented")
+        import tables
+        import csv
+
+        table_file = 'testfile.h5'
+
+        description = dict()
+        description['i'] = tables.Int32Col()
+
+        def pytables_init():
+            return None
+
+        def pytables_load():
+            file = tables.open_file(table_file, mode='w', title='test file')
+            group = file.create_group('/', 'integers', 'integer_data')
+            table = file.create_table(group, 'values', description, "example")
+            values = table.row
+            with open(input_file, 'rb') as csvfile:
+                reader = csv.reader(csvfile)
+                result = [x for x in reader]
+                for x in result:
+                    values['i'] = int(x[0])
+                    values.append()
+            table.flush()
+            file.close()
+
+        def pytables_execute():
+            file = tables.open_file(table_file, mode='r')
+            table = file.root.integers.values
+            result = [x['i'] for x in table.iterrows()]
+            function(numpy.array(result, dtype=numpy.int32))
+
+        def pytables_clear():
+            os.remove('testfile.h5')
+
+        def pytables_final():
+            os.remove(input_file)
+
+        execute_test(input_type, pytables_init, pytables_load, 
pytables_execute, pytables_clear, pytables_final)
     elif str(args_input_database).lower() == "csv":
         import csv
         def csv_init():
@@ -726,7 +793,7 @@ AS $$
         def csv_execute():
             with open(input_file, 'rb') as csvfile:
                 reader = csv.reader(csvfile)
-                result = [x for x in reader]
+                result = [int(x[0]) for x in reader]
                 function(numpy.array(result, dtype=numpy.int32))
 
         def csv_clear():
@@ -745,7 +812,7 @@ AS $$
         def numpy_load():
             with open(input_file, 'rb') as csvfile:
                 reader = csv.reader(csvfile)
-                result = [x for x in reader]
+                result = [int(x[0]) for x in reader]
                 numpy_array = numpy.array(result, dtype=numpy.int32)
                 numpy.save(numpy_binary, numpy_array)
 
@@ -762,7 +829,31 @@ AS $$
 
         execute_test(input_type, numpy_init, numpy_load, numpy_execute, 
numpy_clear, numpy_final)
     elif str(args_input_database).lower() == "castra":
-        print("Not implemented")
+        import castra, csv, shutil, pandas as pd
+        castra_binary = 'data.castra'
+        def castra_init():
+            return None
+
+        def castra_load():
+            with open(input_file, 'rb') as csvfile:
+                reader = csv.reader(csvfile)
+                result = [int(x[0]) for x in reader]
+                numpy_array = numpy.array(result, dtype=numpy.int32)
+                A = pd.DataFrame({'i': numpy_array})
+                c = castra.Castra(castra_binary, template=A)
+                c.extend(A)
+
+        def castra_execute():
+            c = castra.Castra(castra_binary, readonly=True)
+            print function(c[:, 'i'].values)
+
+        def castra_clear():
+            shutil.rmtree(castra_binary)
+
+        def castra_final():
+            os.remove(input_file)
+
+        execute_test(input_type, castra_init, castra_load, castra_execute, 
castra_clear, castra_final)
     elif str(args_input_database).lower() == "numpymemorymap":
         import csv, numpy
         numpy_binary = 'tempfile.npy'
@@ -772,7 +863,7 @@ AS $$
         def numpy_load():
             with open(input_file, 'rb') as csvfile:
                 reader = csv.reader(csvfile)
-                result = [x for x in reader]
+                result = [int(x[0]) for x in reader]
                 numpy_array = numpy.array(result, dtype=numpy.int32)
                 numpy.save(numpy_binary, numpy_array)
 
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
@@ -1,7 +1,7 @@
         
 
 # The base directory of testing, a new folder is created in this base 
directory [$PYAPI_TEST_DIR], and everything is done in that new folder
-export PYAPI_BASE_DIR=/home/mytherin
+export PYAPI_BASE_DIR=/export/scratch1/raasveld
 # The terminal to start mserver with, examples are gnome-terminal, xterm, 
konsole
 export TERMINAL=x-terminal-emulator
 # Port used by the MSERVER
@@ -214,7 +214,7 @@ function postgres_run_single_test() {
     # start server
     setsid $POSTGRES_SERVER_COMMAND > /dev/null && sleep 5
     # call python test script
-    python "$PYAPI_TESTFILE" POSTGRES $1 $2 $3 $MSERVER_PORT $4
+    python "$PYAPI_TESTFILE" $5 $1 $2 $3 $MSERVER_PORT $4
     # finish testing, kill postgres
     killall postgres
 }
@@ -515,16 +515,14 @@ function postgres_test() {
     postgres_run_tests
 }
 
+export DROP_CACHE_COMMAND='echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches'
+
 export IDENTITY_NTESTS=3
 export IDENTITY_SIZES="100"
 
 function postgres_run_tests() {
-    if [ ! -d $PYAPI_OUTPUT_DIR ]; then
-        mkdir $PYAPI_OUTPUT_DIR
-    fi
-    cd $PYAPI_OUTPUT_DIR
-    postgres_run_single_test IDENTITY postgres_identity $IDENTITY_NTESTS 
"$IDENTITY_SIZES"
-    postgres_run_single_test SQROOT postgres_sqroot $IDENTITY_NTESTS 
"$IDENTITY_SIZES"
+    postgres_run_single_test IDENTITY postgres_identity $IDENTITY_NTESTS 
"$IDENTITY_SIZES" POSTGRES
+    postgres_run_single_test SQROOT postgres_sqroot $IDENTITY_NTESTS 
"$IDENTITY_SIZES" POSTGRES
 }
 
 function sqlite_test() {
@@ -577,11 +575,33 @@ function monetdbrapi_test() {
     monetdbmapi_run_single_test RAPI "--set gdk_nr_threads=1 --set 
embedded_r=true" SQROOT monetdbrapi_sqroot $IDENTITY_NTESTS "$IDENTITY_SIZES"
 }
 
-function psycopg_install() {
-    wget http://initd.org/psycopg/tarballs/PSYCOPG-2-6/psycopg2-2.6.1.tar.gz 
&& tar xvzf psycopg2-2.6.1.tar.gz && rm tar xvzf psycopg2-2.6.1.tar.gz && cd 
psycopg2-2.6.1 && python setup.py install --user build_ext --pg-config 
$POSTGRES_BUILD_DIR/bin/pg_config
+function psycopg2_install() {
+    wget http://initd.org/psycopg/tarballs/PSYCOPG-2-6/psycopg2-2.6.1.tar.gz 
&& tar xvzf psycopg2-2.6.1.tar.gz && rm psycopg2-2.6.1.tar.gz && cd 
psycopg2-2.6.1 && python setup.py install --user build_ext --pg-config 
$POSTGRES_BUILD_DIR/bin/pg_config
+}
+
+function psycopg2_test() {
+    postgres_run_single_test IDENTITY psycopg2_identity $IDENTITY_NTESTS 
"$IDENTITY_SIZES" PSYCOPG2
+}
+
+function cython_install() {
+    wget http://cython.org/release/Cython-0.23.1.tar.gz && tar xvzf 
Cython-0.23.1.tar.gz && cd Cython-0.23.1 && python setup.py install --user
+}
+
+function pytables_install() {
+    wget https://github.com/PyTables/PyTables/archive/develop.zip && unzip 
develop.zip && cd PyTables-develop && python setup.py install --user
+}
+
+function pytables_test() {
+    python_run_single_test PYTABLES IDENTITY pytables_identity 
$IDENTITY_NTESTS "$IDENTITY_SIZES"
+    python_run_single_test PYTABLES SQROOT pytables_sqroot $IDENTITY_NTESTS 
"$IDENTITY_SIZES"
 }
 
 function comparison_test() {
+    if [ ! -d $PYAPI_OUTPUT_DIR ]; then
+        mkdir $PYAPI_OUTPUT_DIR
+    fi
+    cd $PYAPI_OUTPUT_DIR
+
     postgres_run_tests
     sqlite_test
     csv_test
@@ -592,8 +612,21 @@ function comparison_test() {
     monetdbpyapi_test
     monetdbpyapimap_test
     monetdbrapi_test
+    psycopg2_test
+    pytables_test
+    castra_test
 }
 
+function castra_install() {
+    wget https://github.com/blaze/castra/archive/master.zip && unzip 
master.zip && cd castra-master && python setup.py install --user
+}
+
+function castra_test() {
+    python_run_single_test CASTRA IDENTITY castra_identity $IDENTITY_NTESTS 
"$IDENTITY_SIZES"
+    python_run_single_test CASTRA SQROOT castra_sqroot $IDENTITY_NTESTS 
"$IDENTITY_SIZES"
+}
+
+
 function comparison_graph() {
     python $PYAPI_GRAPHFILE "SAVE" "Identity" "postgres:postgres_identity.tsv" 
"sqlitemem:sqlitemem_identity.tsv" "sqlitedb:sqlitedb_identity.tsv" 
"csv:csv_identity.tsv" "numpy:numpy_identity.tsv" 
"numpymmap:numpymmap_identity.tsv" 
"monetdbembedded:monetdbembedded_identity.tsv" 
"monetdbmapi:monetdbmapi_identity.tsv" "monetdbpyapi:monetdbpyapi_identity.tsv" 
"monetdbpyapimap:monetdbpyapimap_identity.tsv" 
"monetdbrapi:monetdbrapi_identity.tsv"
     python $PYAPI_GRAPHFILE "SAVE" "Identity [Fast Only]" 
"numpy:numpy_identity.tsv" "numpymmap:numpymmap_identity.tsv" 
"monetdbembedded:monetdbembedded_identity.tsv" 
"monetdbpyapi:monetdbpyapi_identity.tsv" 
"monetdbpyapimap:monetdbpyapimap_identity.tsv" 
"monetdbrapi:monetdbrapi_identity.tsv"
@@ -602,4 +635,3 @@ function comparison_graph() {
     python $PYAPI_GRAPHFILE "SAVE" "Square Root [Fast Only]" 
"numpy:numpy_sqroot.tsv" "numpymmap:numpymmap_sqroot.tsv" 
"monetdbembedded:monetdbembedded_sqroot.tsv" 
"monetdbpyapi:monetdbpyapi_sqroot.tsv" 
"monetdbpyapimap:monetdbpyapimap_sqroot.tsv" 
"monetdbrapi:monetdbrapi_sqroot.tsv"
 
 }
-
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to