summaryrefslogtreecommitdiff
path: root/Examples/python/performance
diff options
context:
space:
mode:
authorStefan Zager <szager@gmail.com>2011-02-10 05:53:04 +0000
committerStefan Zager <szager@gmail.com>2011-02-10 05:53:04 +0000
commit1e094f865e6b5da8f2ac7493a82dcbbd4f44b5f2 (patch)
tree238b172f6dab74cdd3b418ab79a8a4a96e29d2ff /Examples/python/performance
parent6bfc86dee7a909cb66d4235af0a5eac381c0d152 (diff)
downloadswig-1e094f865e6b5da8f2ac7493a82dcbbd4f44b5f2.tar.gz
Added test harness
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12452 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples/python/performance')
-rw-r--r--Examples/python/performance/Makefile3
-rw-r--r--Examples/python/performance/constructor/runme.py18
-rw-r--r--Examples/python/performance/constructor/runme_baseline.py11
-rw-r--r--Examples/python/performance/constructor/runme_builtin.py11
-rw-r--r--Examples/python/performance/constructor/runme_optimized.py11
-rw-r--r--Examples/python/performance/func/runme.py19
-rw-r--r--Examples/python/performance/func/runme_baseline.py11
-rw-r--r--Examples/python/performance/func/runme_builtin.py11
-rw-r--r--Examples/python/performance/func/runme_optimized.py11
-rw-r--r--Examples/python/performance/harness.py30
-rw-r--r--Examples/python/performance/hierarchy/runme.py19
-rw-r--r--Examples/python/performance/hierarchy/runme_baseline.py11
-rw-r--r--Examples/python/performance/hierarchy/runme_builtin.py11
-rw-r--r--Examples/python/performance/hierarchy/runme_optimized.py11
-rw-r--r--Examples/python/performance/hierarchy_operator/runme.py19
-rw-r--r--Examples/python/performance/hierarchy_operator/runme_baseline.py11
-rw-r--r--Examples/python/performance/hierarchy_operator/runme_builtin.py11
-rw-r--r--Examples/python/performance/hierarchy_operator/runme_optimized.py11
-rw-r--r--Examples/python/performance/operator/runme.py19
-rw-r--r--Examples/python/performance/operator/runme_baseline.py11
-rw-r--r--Examples/python/performance/operator/runme_builtin.py11
-rw-r--r--Examples/python/performance/operator/runme_optimized.py11
22 files changed, 66 insertions, 226 deletions
diff --git a/Examples/python/performance/Makefile b/Examples/python/performance/Makefile
index 6f6db22b5..d5ecdbe75 100644
--- a/Examples/python/performance/Makefile
+++ b/Examples/python/performance/Makefile
@@ -10,7 +10,7 @@ else
PYSCRIPT = runme3.py
endif
-SUBDIRS := constructor func hierarchy operator
+SUBDIRS := constructor func hierarchy operator hierarchy_operator
default : all
@@ -36,3 +36,4 @@ $(SUBDIRS) :
$(MAKE) -s -C $* clean
clean : $(SUBDIRS:%=%-clean)
+ rm -f *.pyc
diff --git a/Examples/python/performance/constructor/runme.py b/Examples/python/performance/constructor/runme.py
index 7e50aff16..23577a14d 100644
--- a/Examples/python/performance/constructor/runme.py
+++ b/Examples/python/performance/constructor/runme.py
@@ -1,17 +1,11 @@
#!/usr/bin/env
import sys
-from subprocess import *
+sys.path.append('..')
+import harness
-proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
-
-proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
-
-proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
+def proc (mod) :
+ for i in range(1000000) :
+ x = mod.MyClass()
+harness.run(proc)
diff --git a/Examples/python/performance/constructor/runme_baseline.py b/Examples/python/performance/constructor/runme_baseline.py
deleted file mode 100644
index 0eb284ccc..000000000
--- a/Examples/python/performance/constructor/runme_baseline.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_baseline
-import time
-
-t1 = time.clock()
-for i in range(1000000) :
- x = Simple_baseline.MyClass()
- #x.func()
-t2 = time.clock()
-print "Simple_baseline took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/constructor/runme_builtin.py b/Examples/python/performance/constructor/runme_builtin.py
deleted file mode 100644
index 47ce37864..000000000
--- a/Examples/python/performance/constructor/runme_builtin.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_builtin
-import time
-
-t1 = time.clock()
-for i in range(1000000) :
- x = Simple_builtin.MyClass()
- #x.func()
-t2 = time.clock()
-print "Simple_builtin took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/constructor/runme_optimized.py b/Examples/python/performance/constructor/runme_optimized.py
deleted file mode 100644
index 0c0ed220f..000000000
--- a/Examples/python/performance/constructor/runme_optimized.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_optimized
-import time
-
-t1 = time.clock()
-for i in range(1000000) :
- x = Simple_optimized.MyClass()
- #x.func()
-t2 = time.clock()
-print "Simple_optimized took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/func/runme.py b/Examples/python/performance/func/runme.py
index 7e50aff16..fd2fb175b 100644
--- a/Examples/python/performance/func/runme.py
+++ b/Examples/python/performance/func/runme.py
@@ -1,17 +1,12 @@
#!/usr/bin/env
import sys
-from subprocess import *
+sys.path.append('..')
+import harness
-proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
-
-proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
-
-proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
+def proc (mod) :
+ x = mod.MyClass()
+ for i in range(10000000) :
+ x.func()
+harness.run(proc)
diff --git a/Examples/python/performance/func/runme_baseline.py b/Examples/python/performance/func/runme_baseline.py
deleted file mode 100644
index 6966fd904..000000000
--- a/Examples/python/performance/func/runme_baseline.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_baseline
-import time
-
-t1 = time.clock()
-x = Simple_baseline.MyClass()
-for i in range(10000000) :
- x.func()
-t2 = time.clock()
-print "Simple_baseline took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/func/runme_builtin.py b/Examples/python/performance/func/runme_builtin.py
deleted file mode 100644
index ca2f88ac8..000000000
--- a/Examples/python/performance/func/runme_builtin.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_builtin
-import time
-
-t1 = time.clock()
-x = Simple_builtin.MyClass()
-for i in range(10000000) :
- x.func()
-t2 = time.clock()
-print "Simple_builtin took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/func/runme_optimized.py b/Examples/python/performance/func/runme_optimized.py
deleted file mode 100644
index fe10eb376..000000000
--- a/Examples/python/performance/func/runme_optimized.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_optimized
-import time
-
-t1 = time.clock()
-x = Simple_optimized.MyClass()
-for i in range(10000000) :
- x.func()
-t2 = time.clock()
-print "Simple_optimized took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/harness.py b/Examples/python/performance/harness.py
new file mode 100644
index 000000000..8e9b6041b
--- /dev/null
+++ b/Examples/python/performance/harness.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env
+
+import sys
+import time
+import imp
+from subprocess import *
+
+def run (proc) :
+
+ try :
+ mod = imp.find_module(sys.argv[1])
+ mod = imp.load_module(sys.argv[1], *mod)
+
+ t1 = time.clock()
+ proc(mod)
+ t2 = time.clock()
+ print "%s took %f seconds" % (mod.__name__, t2 - t1)
+
+ except IndexError :
+ proc = Popen([sys.executable, 'runme.py', 'Simple_baseline'], stdout=PIPE)
+ (stdout, stderr) = proc.communicate()
+ print stdout
+
+ proc = Popen([sys.executable, 'runme.py', 'Simple_optimized'], stdout=PIPE)
+ (stdout, stderr) = proc.communicate()
+ print stdout
+
+ proc = Popen([sys.executable, 'runme.py', 'Simple_builtin'], stdout=PIPE)
+ (stdout, stderr) = proc.communicate()
+ print stdout
diff --git a/Examples/python/performance/hierarchy/runme.py b/Examples/python/performance/hierarchy/runme.py
index 7e50aff16..8a57da05e 100644
--- a/Examples/python/performance/hierarchy/runme.py
+++ b/Examples/python/performance/hierarchy/runme.py
@@ -1,17 +1,12 @@
#!/usr/bin/env
import sys
-from subprocess import *
+sys.path.append('..')
+import harness
-proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
-
-proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
-
-proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
+def proc (mod) :
+ x = mod.H()
+ for i in range(10000000) :
+ x.func()
+harness.run(proc)
diff --git a/Examples/python/performance/hierarchy/runme_baseline.py b/Examples/python/performance/hierarchy/runme_baseline.py
deleted file mode 100644
index 584b9fb97..000000000
--- a/Examples/python/performance/hierarchy/runme_baseline.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_baseline
-import time
-
-t1 = time.clock()
-x = Simple_baseline.H()
-for i in range(10000000) :
- x.func()
-t2 = time.clock()
-print "Simple_baseline took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/hierarchy/runme_builtin.py b/Examples/python/performance/hierarchy/runme_builtin.py
deleted file mode 100644
index a095ed223..000000000
--- a/Examples/python/performance/hierarchy/runme_builtin.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_builtin
-import time
-
-t1 = time.clock()
-x = Simple_builtin.H()
-for i in range(10000000) :
- x.func()
-t2 = time.clock()
-print "Simple_builtin took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/hierarchy/runme_optimized.py b/Examples/python/performance/hierarchy/runme_optimized.py
deleted file mode 100644
index c6f20463d..000000000
--- a/Examples/python/performance/hierarchy/runme_optimized.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_optimized
-import time
-
-t1 = time.clock()
-x = Simple_optimized.H()
-for i in range(10000000) :
- x.func()
-t2 = time.clock()
-print "Simple_optimized took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/hierarchy_operator/runme.py b/Examples/python/performance/hierarchy_operator/runme.py
index 7e50aff16..cf200362f 100644
--- a/Examples/python/performance/hierarchy_operator/runme.py
+++ b/Examples/python/performance/hierarchy_operator/runme.py
@@ -1,17 +1,12 @@
#!/usr/bin/env
import sys
-from subprocess import *
+sys.path.append('..')
+import harness
-proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
-
-proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
-
-proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
+def proc (mod) :
+ x = mod.H()
+ for i in range(10000000) :
+ x += i
+harness.run(proc)
diff --git a/Examples/python/performance/hierarchy_operator/runme_baseline.py b/Examples/python/performance/hierarchy_operator/runme_baseline.py
deleted file mode 100644
index 38b4814de..000000000
--- a/Examples/python/performance/hierarchy_operator/runme_baseline.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_baseline
-import time
-
-t1 = time.clock()
-x = Simple_baseline.H()
-for i in range(10000000) :
- x += i
-t2 = time.clock()
-print "Simple_baseline took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/hierarchy_operator/runme_builtin.py b/Examples/python/performance/hierarchy_operator/runme_builtin.py
deleted file mode 100644
index 2ce0459a8..000000000
--- a/Examples/python/performance/hierarchy_operator/runme_builtin.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_builtin
-import time
-
-t1 = time.clock()
-x = Simple_builtin.H()
-for i in range(10000000) :
- x += i
-t2 = time.clock()
-print "Simple_builtin took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/hierarchy_operator/runme_optimized.py b/Examples/python/performance/hierarchy_operator/runme_optimized.py
deleted file mode 100644
index 7d849051b..000000000
--- a/Examples/python/performance/hierarchy_operator/runme_optimized.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_optimized
-import time
-
-t1 = time.clock()
-x = Simple_optimized.H()
-for i in range(10000000) :
- x += i
-t2 = time.clock()
-print "Simple_optimized took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/operator/runme.py b/Examples/python/performance/operator/runme.py
index 7e50aff16..61a0e8edc 100644
--- a/Examples/python/performance/operator/runme.py
+++ b/Examples/python/performance/operator/runme.py
@@ -1,17 +1,12 @@
#!/usr/bin/env
import sys
-from subprocess import *
+sys.path.append('..')
+import harness
-proc = Popen([sys.executable, 'runme_baseline.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
-
-proc = Popen([sys.executable, 'runme_optimized.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
-
-proc = Popen([sys.executable, 'runme_builtin.py'], stdout=PIPE)
-(stdout, stderr) = proc.communicate()
-print stdout
+def proc (mod) :
+ x = mod.MyClass()
+ for i in range(10000000) :
+ x = x + i
+harness.run(proc)
diff --git a/Examples/python/performance/operator/runme_baseline.py b/Examples/python/performance/operator/runme_baseline.py
deleted file mode 100644
index f7fa9094b..000000000
--- a/Examples/python/performance/operator/runme_baseline.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_baseline
-import time
-
-t1 = time.clock()
-x = Simple_baseline.MyClass()
-for i in range(10000000) :
- x = x + i
-t2 = time.clock()
-print "Simple_baseline took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/operator/runme_builtin.py b/Examples/python/performance/operator/runme_builtin.py
deleted file mode 100644
index 73da3afb2..000000000
--- a/Examples/python/performance/operator/runme_builtin.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_builtin
-import time
-
-t1 = time.clock()
-x = Simple_builtin.MyClass()
-for i in range(10000000) :
- x = x + i
-t2 = time.clock()
-print "Simple_builtin took %f seconds" % (t2 - t1)
diff --git a/Examples/python/performance/operator/runme_optimized.py b/Examples/python/performance/operator/runme_optimized.py
deleted file mode 100644
index 4f22e0bda..000000000
--- a/Examples/python/performance/operator/runme_optimized.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-
-import Simple_optimized
-import time
-
-t1 = time.clock()
-x = Simple_optimized.MyClass()
-for i in range(10000000) :
- x = x + i
-t2 = time.clock()
-print "Simple_optimized took %f seconds" % (t2 - t1)