aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/pybind11/docs/benchmark.py
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/pybind11/docs/benchmark.py')
-rw-r--r--3rdparty/pybind11/docs/benchmark.py33
1 files changed, 14 insertions, 19 deletions
diff --git a/3rdparty/pybind11/docs/benchmark.py b/3rdparty/pybind11/docs/benchmark.py
index 33d78fb4..2150b6ca 100644
--- a/3rdparty/pybind11/docs/benchmark.py
+++ b/3rdparty/pybind11/docs/benchmark.py
@@ -1,8 +1,6 @@
-# -*- coding: utf-8 -*-
-import random
-import os
-import time
import datetime as dt
+import os
+import random
nfns = 4 # Functions per class
nargs = 4 # Arguments per function
@@ -13,20 +11,20 @@ def generate_dummy_code_pybind11(nclasses=10):
bindings = ""
for cl in range(nclasses):
- decl += "class cl%03i;\n" % cl
+ decl += f"class cl{cl:03};\n"
decl += "\n"
for cl in range(nclasses):
- decl += "class cl%03i {\n" % cl
+ decl += f"class {cl:03} {{\n"
decl += "public:\n"
- bindings += ' py::class_<cl%03i>(m, "cl%03i")\n' % (cl, cl)
+ bindings += f' py::class_<cl{cl:03}>(m, "cl{cl:03}")\n'
for fn in range(nfns):
ret = random.randint(0, nclasses - 1)
params = [random.randint(0, nclasses - 1) for i in range(nargs)]
- decl += " cl%03i *fn_%03i(" % (ret, fn)
- decl += ", ".join("cl%03i *" % p for p in params)
+ decl += f" cl{ret:03} *fn_{fn:03}("
+ decl += ", ".join(f"cl{p:03} *" for p in params)
decl += ");\n"
- bindings += ' .def("fn_%03i", &cl%03i::fn_%03i)\n' % (fn, cl, fn)
+ bindings += f' .def("fn_{fn:03}", &cl{cl:03}::fn_{fn:03})\n'
decl += "};\n\n"
bindings += " ;\n"
@@ -44,23 +42,20 @@ def generate_dummy_code_boost(nclasses=10):
bindings = ""
for cl in range(nclasses):
- decl += "class cl%03i;\n" % cl
+ decl += f"class cl{cl:03};\n"
decl += "\n"
for cl in range(nclasses):
decl += "class cl%03i {\n" % cl
decl += "public:\n"
- bindings += ' py::class_<cl%03i>("cl%03i")\n' % (cl, cl)
+ bindings += f' py::class_<cl{cl:03}>("cl{cl:03}")\n'
for fn in range(nfns):
ret = random.randint(0, nclasses - 1)
params = [random.randint(0, nclasses - 1) for i in range(nargs)]
- decl += " cl%03i *fn_%03i(" % (ret, fn)
- decl += ", ".join("cl%03i *" % p for p in params)
+ decl += f" cl{ret:03} *fn_{fn:03}("
+ decl += ", ".join(f"cl{p:03} *" for p in params)
decl += ");\n"
- bindings += (
- ' .def("fn_%03i", &cl%03i::fn_%03i, py::return_value_policy<py::manage_new_object>())\n'
- % (fn, cl, fn)
- )
+ bindings += f' .def("fn_{fn:03}", &cl{cl:03}::fn_{fn:03}, py::return_value_policy<py::manage_new_object>())\n'
decl += "};\n\n"
bindings += " ;\n"
@@ -76,7 +71,7 @@ def generate_dummy_code_boost(nclasses=10):
for codegen in [generate_dummy_code_pybind11, generate_dummy_code_boost]:
print("{")
for i in range(0, 10):
- nclasses = 2 ** i
+ nclasses = 2**i
with open("test.cpp", "w") as f:
f.write(codegen(nclasses))
n1 = dt.datetime.now()