15 for cl
in range(nclasses):
16 decl +=
"class cl%03i;\n" % cl
19 for cl
in range(nclasses):
20 decl +=
"class cl%03i {\n" % cl
22 bindings +=
' py::class_<cl%03i>(m, "cl%03i")\n' % (cl, cl)
23 for fn
in range(nfns):
24 ret = random.randint(0, nclasses - 1)
25 params = [random.randint(0, nclasses - 1)
for i
in range(nargs)]
26 decl +=
" cl%03i *fn_%03i(" % (ret, fn)
27 decl +=
", ".join(
"cl%03i *" % p
for p
in params)
29 bindings +=
' .def("fn_%03i", &cl%03i::fn_%03i)\n' % \
34 result =
"#include <pybind11/pybind11.h>\n\n" 35 result +=
"namespace py = pybind11;\n\n" 37 result +=
"PYBIND11_MODULE(example, m) {\n" 47 for cl
in range(nclasses):
48 decl +=
"class cl%03i;\n" % cl
51 for cl
in range(nclasses):
52 decl +=
"class cl%03i {\n" % cl
54 bindings +=
' py::class_<cl%03i>("cl%03i")\n' % (cl, cl)
55 for fn
in range(nfns):
56 ret = random.randint(0, nclasses - 1)
57 params = [random.randint(0, nclasses - 1)
for i
in range(nargs)]
58 decl +=
" cl%03i *fn_%03i(" % (ret, fn)
59 decl +=
", ".join(
"cl%03i *" % p
for p
in params)
61 bindings +=
' .def("fn_%03i", &cl%03i::fn_%03i, py::return_value_policy<py::manage_new_object>())\n' % \
66 result =
"#include <boost/python.hpp>\n\n" 67 result +=
"namespace py = boost::python;\n\n" 69 result +=
"BOOST_PYTHON_MODULE(example) {\n" 75 for codegen
in [generate_dummy_code_pybind11, generate_dummy_code_boost]:
77 for i
in range(0, 10):
79 with open(
"test.cpp",
"w")
as f:
80 f.write(codegen(nclasses))
81 n1 = dt.datetime.now()
82 os.system(
"g++ -Os -shared -rdynamic -undefined dynamic_lookup " 83 "-fvisibility=hidden -std=c++14 test.cpp -I include " 84 "-I /System/Library/Frameworks/Python.framework/Headers -o test.so")
85 n2 = dt.datetime.now()
86 elapsed = (n2 - n1).total_seconds()
87 size = os.stat(
'test.so').st_size
88 print(
" {%i, %f, %i}," % (nclasses * nfns, elapsed, size))
void print(const Matrix &A, const string &s, ostream &stream)
def generate_dummy_code_pybind11(nclasses=10)
def generate_dummy_code_boost(nclasses=10)