⚲
Project
General
Profile
Sign in
Register
Home
Projects
Search
:
ndn-cxx
All Projects
NFD
»
ndn-cxx
Overview
Activity
Roadmap
Issues
Wiki
Download (779 Bytes)
Task #1912
ยป sharedptr-bench.cpp
Junxiao Shi
, 08/22/2014 09:38 PM
// g++ sharedptr-bench.cpp -lrt
#include
<time.h>
#include
<stdio.h>
#include
<boost/shared_ptr.hpp>
#include
<boost/make_shared.hpp>
using
boost
::
shared_ptr
;
using
boost
::
make_shared
;
struct
A
{
int
i
;
};
void
f1
(
const
shared_ptr
<
A
>&
a
)
{
++
a
->
i
;
}
void
f2
(
shared_ptr
<
A
>
a
)
{
++
a
->
i
;
}
int
main
()
{
shared_ptr
<
A
>
a
=
make_shared
<
A
>
();
timespec
t1
,
t2
,
t3
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
t1
);
for
(
int
k
=
0
;
k
<
1000000
;
++
k
)
{
f1
(
a
);
}
clock_gettime
(
CLOCK_MONOTONIC
,
&
t2
);
for
(
int
k
=
0
;
k
<
1000000
;
++
k
)
{
f2
(
a
);
}
clock_gettime
(
CLOCK_MONOTONIC
,
&
t3
);
printf
(
"f1 %ld
\n
"
,
(
t2
.
tv_sec
-
t1
.
tv_sec
)
*
1000000000
+
(
t2
.
tv_nsec
-
t1
.
tv_nsec
));
printf
(
"f2 %ld
\n
"
,
(
t3
.
tv_sec
-
t2
.
tv_sec
)
*
1000000000
+
(
t3
.
tv_nsec
-
t2
.
tv_nsec
));
}
(1-1/1)
Loading...