Commit 677ec875 by Ralf W. Grosse-Kunstleve

Merge branch 'test_unique_ptr_member' into pr2672_use_smart_holder_as_default

parents c338e13a 40d91ede
...@@ -46,6 +46,7 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(hc::nb_sh) ...@@ -46,6 +46,7 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(hc::nb_sh)
PYBIND11_MODULE(pybind11_ubench_holder_comparison, m) { PYBIND11_MODULE(pybind11_ubench_holder_comparison, m) {
using namespace hc; using namespace hc;
m.def("sizeof_smart_holder", []() { return sizeof(py::smart_holder); });
wrap_number_bucket<nb_up, std::unique_ptr<nb_up>>(m, "number_bucket_up"); wrap_number_bucket<nb_up, std::unique_ptr<nb_up>>(m, "number_bucket_up");
wrap_number_bucket<nb_sp, std::shared_ptr<nb_sp>>(m, "number_bucket_sp"); wrap_number_bucket<nb_sp, std::shared_ptr<nb_sp>>(m, "number_bucket_sp");
wrap_number_bucket<nb_pu, padded_unique_ptr<nb_pu>>(m, "number_bucket_pu"); wrap_number_bucket<nb_pu, padded_unique_ptr<nb_pu>>(m, "number_bucket_pu");
......
...@@ -54,6 +54,25 @@ def run(args): ...@@ -54,6 +54,25 @@ def run(args):
num_samples, num_samples,
selected_holder_type, selected_holder_type,
) )
pflush("sizeof_smart_holder:", m.sizeof_smart_holder())
def find_call_repetitions(
callable,
time_delta_floor=1.0e-6,
target_elapsed_secs_multiplier=1.05, # Empirical.
target_elapsed_secs_tolerance=0.05,
max_iterations=100,
):
td_target = (
call_repetitions_target_elapsed_secs * target_elapsed_secs_multiplier
)
crd = call_repetitions_first_pass
for _ in range(max_iterations):
td = callable(crd)
crd = max(1, int(td_target * crd / max(td, time_delta_floor)))
if abs(td - td_target) / td_target < target_elapsed_secs_tolerance:
return crd
raise RuntimeError("find_call_repetitions failure: max_iterations exceeded.")
for size_exponent in range( for size_exponent in range(
size_exponent_min, size_exponent_max + 1, size_exponent_step size_exponent_min, size_exponent_max + 1, size_exponent_step
...@@ -61,7 +80,7 @@ def run(args): ...@@ -61,7 +80,7 @@ def run(args):
data_size = 2 ** size_exponent data_size = 2 ** size_exponent
pflush(data_size, "data_size") pflush(data_size, "data_size")
ratios = collections.defaultdict(list) ratios = collections.defaultdict(list)
call_repetitions_dynamic = None call_repetitions = None
for _ in range(num_samples): for _ in range(num_samples):
row_0 = None row_0 = None
for nb_label, nb_type in [ for nb_label, nb_type in [
...@@ -77,32 +96,27 @@ def run(args): ...@@ -77,32 +96,27 @@ def run(args):
continue continue
nb1 = nb_type(data_size) nb1 = nb_type(data_size)
nb2 = nb_type(data_size) nb2 = nb_type(data_size)
if call_repetitions_dynamic is None:
assert int(round(nb1.sum())) == data_size def many_sum(call_repetitions):
t0 = time.time()
for _ in range(call_repetitions_first_pass):
nb1.sum()
td_sum = time.time() - t0
call_repetitions_dynamic = max(
call_repetitions_first_pass,
int(
call_repetitions_target_elapsed_secs
* call_repetitions_first_pass
/ max(td_sum, 1.0e-6)
)
+ 1,
)
pflush(call_repetitions_dynamic, "call_repetitions_dynamic")
assert int(round(nb1.sum())) == data_size assert int(round(nb1.sum())) == data_size
t0 = time.time() t0 = time.time()
for _ in range(call_repetitions_dynamic): for _ in range(call_repetitions):
nb1.sum() nb1.sum()
td_sum = time.time() - t0 return time.time() - t0
def many_add(call_repetitions):
assert nb1.add(nb2) == data_size assert nb1.add(nb2) == data_size
t0 = time.time() t0 = time.time()
for _ in range(call_repetitions_dynamic): for _ in range(call_repetitions):
nb1.add(nb2) nb1.add(nb2)
td_add = time.time() - t0 return time.time() - t0
if call_repetitions is None:
call_repetitions = find_call_repetitions(many_sum)
pflush(call_repetitions, "call_repetitions")
td_sum = many_sum(call_repetitions)
td_add = many_add(call_repetitions)
row = [td_sum, td_add] row = [td_sum, td_add]
if row_0 is None: if row_0 is None:
pflush(" Sum Add ratS ratA") pflush(" Sum Add ratS ratA")
......
# -*- coding: utf-8 -*-
"""Extract mean ratios from holder_comparison.py output."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
def run(args):
assert len(args) == 1, "log_holder_comparison.txt"
log_lines = open(args[0]).read().splitlines()
for ratx in ("_ratS ", "_ratA "):
print(ratx)
header = None
header_row = None
data_row = None
data_row_buffer = []
def show():
if header_row:
if header is None:
print(",".join(header_row))
else:
assert header == header_row
if data_row is not None:
print(",".join(data_row))
data_row_buffer.append(data_row)
return header_row
for line in log_lines:
if line.endswith(" data_size"):
header = show()
flds = line.split()
assert len(flds) == 2
header_row = ["data_size"]
data_row = [flds[0]]
elif line.endswith(" call_repetitions"):
flds = line.split()
assert len(flds) == 2
header_row.append("calls")
data_row.append(flds[0])
header_row.append("up")
data_row.append("1.000")
elif line[2:].startswith(ratx):
flds = line.split()
assert len(flds) == 4
header_row.append(line[:2])
data_row.append(flds[2])
show()
print("Scaled to last column:")
print(",".join(header_row))
for data_row in data_row_buffer:
data_row_rescaled = data_row[:2]
unit = float(data_row[-1])
for fld in data_row[2:]:
data_row_rescaled.append("%.3f" % (float(fld) / unit))
print(",".join(data_row_rescaled))
if __name__ == "__main__":
run(args=sys.argv[1:])
from "pybind11/ubench/number_bucket.h":
namespace `pybind11_ubench`:
class `number_bucket<0>` as number_bucket_pc:
def __init__(self, data_size: int = default)
def sum(self) -> float
def add(self, other: number_bucket_pc) -> int
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment