Merged from branches/szager-python-builtin
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12596 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
commit
bc9a32a658
53 changed files with 3413 additions and 563 deletions
35
Examples/python/performance/Makefile
Normal file
35
Examples/python/performance/Makefile
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
ifeq (,$(PY3))
|
||||
PYSCRIPT = runme.py
|
||||
else
|
||||
PYSCRIPT = runme3.py
|
||||
endif
|
||||
|
||||
default : all
|
||||
|
||||
include ../../Makefile
|
||||
|
||||
SUBDIRS := constructor func hierarchy operator hierarchy_operator
|
||||
|
||||
all : $(SUBDIRS:%=%-build)
|
||||
@for subdir in $(SUBDIRS); do \
|
||||
echo Running $$subdir test... ; \
|
||||
echo -------------------------------------------------------------------------------- ; \
|
||||
cd $$subdir; \
|
||||
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT); \
|
||||
cd ..; \
|
||||
done
|
||||
|
||||
$(SUBDIRS) :
|
||||
$(MAKE) -C $@
|
||||
@echo Running $$subdir test...
|
||||
@echo --------------------------------------------------------------------------------
|
||||
cd $@ && env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT)
|
||||
|
||||
%-build :
|
||||
$(MAKE) -C $*
|
||||
|
||||
%-clean :
|
||||
$(MAKE) -s -C $* clean
|
||||
|
||||
clean : $(SUBDIRS:%=%-clean)
|
||||
rm -f *.pyc
|
||||
21
Examples/python/performance/constructor/Makefile
Normal file
21
Examples/python/performance/constructor/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TOP = ../../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
TARGET = Simple
|
||||
INTERFACE = Simple.i
|
||||
|
||||
all :
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
|
||||
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
|
||||
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
|
||||
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static :
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean :
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
8
Examples/python/performance/constructor/Simple.i
Normal file
8
Examples/python/performance/constructor/Simple.i
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
%inline %{
|
||||
class MyClass {
|
||||
public:
|
||||
MyClass () {}
|
||||
~MyClass () {}
|
||||
void func () {}
|
||||
};
|
||||
%}
|
||||
11
Examples/python/performance/constructor/runme.py
Normal file
11
Examples/python/performance/constructor/runme.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import harness
|
||||
|
||||
def proc (mod) :
|
||||
for i in range(1000000) :
|
||||
x = mod.MyClass()
|
||||
|
||||
harness.run(proc)
|
||||
23
Examples/python/performance/func/Makefile
Normal file
23
Examples/python/performance/func/Makefile
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
TOP = ../../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
TARGET = Simple
|
||||
INTERFACE = Simple.i
|
||||
|
||||
default : all
|
||||
|
||||
all :
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
|
||||
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
|
||||
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
|
||||
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static :
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean :
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
8
Examples/python/performance/func/Simple.i
Normal file
8
Examples/python/performance/func/Simple.i
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
%inline %{
|
||||
class MyClass {
|
||||
public:
|
||||
MyClass () {}
|
||||
~MyClass () {}
|
||||
void func () {}
|
||||
};
|
||||
%}
|
||||
12
Examples/python/performance/func/runme.py
Normal file
12
Examples/python/performance/func/runme.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import harness
|
||||
|
||||
def proc (mod) :
|
||||
x = mod.MyClass()
|
||||
for i in range(10000000) :
|
||||
x.func()
|
||||
|
||||
harness.run(proc)
|
||||
30
Examples/python/performance/harness.py
Normal file
30
Examples/python/performance/harness.py
Normal file
|
|
@ -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
|
||||
23
Examples/python/performance/hierarchy/Makefile
Normal file
23
Examples/python/performance/hierarchy/Makefile
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
TOP = ../../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
TARGET = Simple
|
||||
INTERFACE = Simple.i
|
||||
|
||||
default : all
|
||||
|
||||
all :
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
|
||||
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
|
||||
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
|
||||
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static :
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean :
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
52
Examples/python/performance/hierarchy/Simple.i
Normal file
52
Examples/python/performance/hierarchy/Simple.i
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
%inline %{
|
||||
|
||||
class A {
|
||||
public:
|
||||
A () {}
|
||||
~A () {}
|
||||
void func () {}
|
||||
};
|
||||
|
||||
class B : public A {
|
||||
public:
|
||||
B () {}
|
||||
~B () {}
|
||||
};
|
||||
|
||||
class C : public B {
|
||||
public:
|
||||
C () {}
|
||||
~C () {}
|
||||
};
|
||||
|
||||
class D : public C {
|
||||
public:
|
||||
D () {}
|
||||
~D () {}
|
||||
};
|
||||
|
||||
class E : public D {
|
||||
public:
|
||||
E () {}
|
||||
~E () {}
|
||||
};
|
||||
|
||||
class F : public E {
|
||||
public:
|
||||
F () {}
|
||||
~F () {}
|
||||
};
|
||||
|
||||
class G : public F {
|
||||
public:
|
||||
G () {}
|
||||
~G () {}
|
||||
};
|
||||
|
||||
class H : public G {
|
||||
public:
|
||||
H () {}
|
||||
~H () {}
|
||||
};
|
||||
|
||||
%}
|
||||
12
Examples/python/performance/hierarchy/runme.py
Normal file
12
Examples/python/performance/hierarchy/runme.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import harness
|
||||
|
||||
def proc (mod) :
|
||||
x = mod.H()
|
||||
for i in range(10000000) :
|
||||
x.func()
|
||||
|
||||
harness.run(proc)
|
||||
23
Examples/python/performance/hierarchy_operator/Makefile
Normal file
23
Examples/python/performance/hierarchy_operator/Makefile
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
TOP = ../../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
TARGET = Simple
|
||||
INTERFACE = Simple.i
|
||||
|
||||
default : all
|
||||
|
||||
all :
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
|
||||
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
|
||||
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
|
||||
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static :
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean :
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
53
Examples/python/performance/hierarchy_operator/Simple.i
Normal file
53
Examples/python/performance/hierarchy_operator/Simple.i
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
%inline %{
|
||||
|
||||
class A {
|
||||
public:
|
||||
A () {}
|
||||
~A () {}
|
||||
void func () {}
|
||||
A& operator+= (int i) { return *this; }
|
||||
};
|
||||
|
||||
class B : public A {
|
||||
public:
|
||||
B () {}
|
||||
~B () {}
|
||||
};
|
||||
|
||||
class C : public B {
|
||||
public:
|
||||
C () {}
|
||||
~C () {}
|
||||
};
|
||||
|
||||
class D : public C {
|
||||
public:
|
||||
D () {}
|
||||
~D () {}
|
||||
};
|
||||
|
||||
class E : public D {
|
||||
public:
|
||||
E () {}
|
||||
~E () {}
|
||||
};
|
||||
|
||||
class F : public E {
|
||||
public:
|
||||
F () {}
|
||||
~F () {}
|
||||
};
|
||||
|
||||
class G : public F {
|
||||
public:
|
||||
G () {}
|
||||
~G () {}
|
||||
};
|
||||
|
||||
class H : public G {
|
||||
public:
|
||||
H () {}
|
||||
~H () {}
|
||||
};
|
||||
|
||||
%}
|
||||
12
Examples/python/performance/hierarchy_operator/runme.py
Normal file
12
Examples/python/performance/hierarchy_operator/runme.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import harness
|
||||
|
||||
def proc (mod) :
|
||||
x = mod.H()
|
||||
for i in range(10000000) :
|
||||
x += i
|
||||
|
||||
harness.run(proc)
|
||||
23
Examples/python/performance/operator/Makefile
Normal file
23
Examples/python/performance/operator/Makefile
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
TOP = ../../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
TARGET = Simple
|
||||
INTERFACE = Simple.i
|
||||
|
||||
default : all
|
||||
|
||||
all :
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
|
||||
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
|
||||
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
|
||||
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static :
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean :
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
8
Examples/python/performance/operator/Simple.i
Normal file
8
Examples/python/performance/operator/Simple.i
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
%inline %{
|
||||
class MyClass {
|
||||
public:
|
||||
MyClass () {}
|
||||
~MyClass () {}
|
||||
MyClass& operator+ (int i) { return *this; }
|
||||
};
|
||||
%}
|
||||
12
Examples/python/performance/operator/runme.py
Normal file
12
Examples/python/performance/operator/runme.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
import harness
|
||||
|
||||
def proc (mod) :
|
||||
x = mod.MyClass()
|
||||
for i in range(10000000) :
|
||||
x = x + i
|
||||
|
||||
harness.run(proc)
|
||||
Loading…
Add table
Add a link
Reference in a new issue