Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
677ec875
Commit
677ec875
authored
Feb 22, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test_unique_ptr_member' into pr2672_use_smart_holder_as_default
parents
c338e13a
40d91ede
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
24 deletions
+111
-24
ubench/holder_comparison.cpp
+1
-0
ubench/holder_comparison.py
+38
-24
ubench/holder_comparison_extract_sheet_data.py
+66
-0
ubench/python/number_bucket.clif
+6
-0
No files found.
ubench/holder_comparison.cpp
View file @
677ec875
...
...
@@ -46,6 +46,7 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(hc::nb_sh)
PYBIND11_MODULE
(
pybind11_ubench_holder_comparison
,
m
)
{
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_sp
,
std
::
shared_ptr
<
nb_sp
>>
(
m
,
"number_bucket_sp"
);
wrap_number_bucket
<
nb_pu
,
padded_unique_ptr
<
nb_pu
>>
(
m
,
"number_bucket_pu"
);
...
...
ubench/holder_comparison.py
View file @
677ec875
...
...
@@ -54,6 +54,25 @@ def run(args):
num_samples
,
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
(
size_exponent_min
,
size_exponent_max
+
1
,
size_exponent_step
...
...
@@ -61,7 +80,7 @@ def run(args):
data_size
=
2
**
size_exponent
pflush
(
data_size
,
"data_size"
)
ratios
=
collections
.
defaultdict
(
list
)
call_repetitions
_dynamic
=
None
call_repetitions
=
None
for
_
in
range
(
num_samples
):
row_0
=
None
for
nb_label
,
nb_type
in
[
...
...
@@ -77,32 +96,27 @@ def run(args):
continue
nb1
=
nb_type
(
data_size
)
nb2
=
nb_type
(
data_size
)
if
call_repetitions_dynamic
is
None
:
def
many_sum
(
call_repetitions
):
assert
int
(
round
(
nb1
.
sum
()))
==
data_size
t0
=
time
.
time
()
for
_
in
range
(
call_repetitions
_first_pass
):
for
_
in
range
(
call_repetitions
):
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
t0
=
time
.
time
()
for
_
in
range
(
call_repetitions_dynamic
):
nb1
.
sum
()
td_sum
=
time
.
time
()
-
t0
assert
nb1
.
add
(
nb2
)
==
data_size
t0
=
time
.
time
()
for
_
in
range
(
call_repetitions_dynamic
):
nb1
.
add
(
nb2
)
td_add
=
time
.
time
()
-
t0
return
time
.
time
()
-
t0
def
many_add
(
call_repetitions
):
assert
nb1
.
add
(
nb2
)
==
data_size
t0
=
time
.
time
()
for
_
in
range
(
call_repetitions
):
nb1
.
add
(
nb2
)
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
]
if
row_0
is
None
:
pflush
(
" Sum Add ratS ratA"
)
...
...
ubench/holder_comparison_extract_sheet_data.py
0 → 100644
View file @
677ec875
# -*- 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
(
"
%.3
f"
%
(
float
(
fld
)
/
unit
))
print
(
","
.
join
(
data_row_rescaled
))
if
__name__
==
"__main__"
:
run
(
args
=
sys
.
argv
[
1
:])
ubench/python/number_bucket.clif
0 → 100644
View file @
677ec875
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment