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
09644196
Commit
09644196
authored
Feb 20, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Breaking out number_bucket.h, adding hook for also collecting performance data for PyCLIF.
parent
baf51b4e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
50 deletions
+68
-50
ubench/holder_comparison.cpp
+6
-48
ubench/holder_comparison.py
+7
-2
ubench/number_bucket.h
+55
-0
No files found.
ubench/holder_comparison.cpp
View file @
09644196
#include <pybind11/smart_holder.h>
#include "number_bucket.h"
#include <cstddef>
#include <memory>
#include <vector>
namespace
hc
{
// holder comparison
template
<
int
Serial
>
struct
number_bucket
{
std
::
vector
<
double
>
data
;
explicit
number_bucket
(
std
::
size_t
data_size
=
0
)
:
data
(
data_size
,
1.0
)
{}
double
sum
()
const
{
std
::
size_t
n
=
0
;
double
s
=
0
;
const
double
*
a
=
&*
data
.
begin
();
const
double
*
e
=
&*
data
.
end
();
while
(
a
!=
e
)
{
s
+=
*
a
++
;
n
++
;
}
if
(
n
!=
data
.
size
())
{
throw
std
::
runtime_error
(
"Internal consistency failure (sum)."
);
}
return
s
;
}
std
::
size_t
add
(
const
number_bucket
&
other
)
{
if
(
other
.
data
.
size
()
!=
data
.
size
())
{
throw
std
::
runtime_error
(
"Incompatible data sizes."
);
}
std
::
size_t
n
=
0
;
double
*
a
=
&*
data
.
begin
();
const
double
*
e
=
&*
data
.
end
();
const
double
*
b
=
&*
other
.
data
.
begin
();
while
(
a
!=
e
)
{
*
a
++
+=
*
b
++
;
n
++
;
}
return
n
;
}
private
:
number_bucket
(
const
number_bucket
&
)
=
delete
;
number_bucket
(
number_bucket
&&
)
=
delete
;
number_bucket
&
operator
=
(
const
number_bucket
&
)
=
delete
;
number_bucket
&
operator
=
(
number_bucket
&&
)
=
delete
;
};
using
nb_up
=
pybind11_ubench
::
number_bucket
<
1
>
;
using
nb_sp
=
pybind11_ubench
::
number_bucket
<
2
>
;
using
nb_pu
=
pybind11_ubench
::
number_bucket
<
3
>
;
using
nb_sh
=
pybind11_ubench
::
number_bucket
<
4
>
;
namespace
py
=
pybind11
;
...
...
@@ -69,11 +32,6 @@ public:
T
*
get
()
{
return
ptr
.
get
();
}
};
using
nb_up
=
number_bucket
<
0
>
;
using
nb_sp
=
number_bucket
<
1
>
;
using
nb_pu
=
number_bucket
<
2
>
;
using
nb_sh
=
number_bucket
<
3
>
;
static_assert
(
sizeof
(
padded_unique_ptr
<
nb_pu
>
)
==
sizeof
(
py
::
smart_holder
),
"Unexpected sizeof mismatch."
);
...
...
ubench/holder_comparison.py
View file @
09644196
...
...
@@ -11,6 +11,8 @@ import collections
import
sys
import
time
number_bucket_pc
=
None
def
pflush
(
*
args
,
**
kwargs
):
result
=
print
(
*
args
,
**
kwargs
)
...
...
@@ -28,7 +30,7 @@ def run(args):
call_repetitions_first_pass
=
100
call_repetitions_target_elapsed_secs
=
0.1
num_samples
=
10
selected_holder_type
=
"
*
"
selected_holder_type
=
"
all
"
else
:
assert
len
(
args
)
==
7
,
(
"size_exponent_min size_exponent_max size_exponent_step"
...
...
@@ -67,8 +69,11 @@ def run(args):
(
"sp"
,
m
.
number_bucket_sp
),
(
"pu"
,
m
.
number_bucket_pu
),
(
"sh"
,
m
.
number_bucket_sh
),
(
"pc"
,
number_bucket_pc
),
]:
if
selected_holder_type
!=
"*"
and
nb_label
!=
selected_holder_type
:
if
nb_label
==
"pc"
and
nb_type
is
None
:
continue
if
selected_holder_type
!=
"all"
and
nb_label
!=
selected_holder_type
:
continue
nb1
=
nb_type
(
data_size
)
nb2
=
nb_type
(
data_size
)
...
...
ubench/number_bucket.h
0 → 100644
View file @
09644196
#pragma once
#include <cstddef>
#include <exception>
#include <iostream>
#include <vector>
namespace
pybind11_ubench
{
template
<
int
Serial
>
struct
number_bucket
{
std
::
vector
<
double
>
data
;
explicit
number_bucket
(
std
::
size_t
data_size
=
0
)
:
data
(
data_size
,
1
.
0
)
{}
double
sum
()
const
{
std
::
size_t
n
=
0
;
double
s
=
0
;
const
double
*
a
=
&*
data
.
begin
();
const
double
*
e
=
&*
data
.
end
();
while
(
a
!=
e
)
{
s
+=
*
a
++
;
n
++
;
}
if
(
n
!=
data
.
size
())
{
std
::
cerr
<<
"Internal consistency failure (sum)."
<<
std
::
endl
;
std
::
terminate
();
}
return
s
;
}
std
::
size_t
add
(
const
number_bucket
&
other
)
{
if
(
other
.
data
.
size
()
!=
data
.
size
())
{
std
::
cerr
<<
"Incompatible data sizes (add)."
<<
std
::
endl
;
std
::
terminate
();
}
std
::
size_t
n
=
0
;
double
*
a
=
&*
data
.
begin
();
const
double
*
e
=
&*
data
.
end
();
const
double
*
b
=
&*
other
.
data
.
begin
();
while
(
a
!=
e
)
{
*
a
++
+=
*
b
++
;
n
++
;
}
return
n
;
}
private
:
number_bucket
(
const
number_bucket
&
)
=
delete
;
number_bucket
(
number_bucket
&&
)
=
delete
;
number_bucket
&
operator
=
(
const
number_bucket
&
)
=
delete
;
number_bucket
&
operator
=
(
number_bucket
&&
)
=
delete
;
};
}
// namespace pybind11_ubench
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