Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
5973b4c6
Commit
5973b4c6
authored
Mar 31, 2013
by
Timothee "TTimo" Besset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Windows friendly replacement for gettimeofday
parent
574fe35b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
13 deletions
+73
-13
local_thr.cpp
perf/local_thr.cpp
+38
-6
remote_thr.cpp
perf/remote_thr.cpp
+35
-7
No files found.
perf/local_thr.cpp
View file @
5973b4c6
...
@@ -26,7 +26,12 @@
...
@@ -26,7 +26,12 @@
#include <string.h>
#include <string.h>
#include <time.h>
#include <time.h>
#include <limits.h>
#include <limits.h>
#include "platform.hpp"
#ifndef ZMQ_HAVE_WINDOWS
#include <sys/time.h>
#include <sys/time.h>
#endif
#define ZMSG 1
#define ZMSG 1
#define DATA 0
#define DATA 0
...
@@ -41,9 +46,23 @@ struct US_TIMER{
...
@@ -41,9 +46,23 @@ struct US_TIMER{
/* Records the current timer state
/* Records the current timer state
*/
*/
void
tm_init
(
US_TIMER
*
t
){
void
tm_init
(
US_TIMER
*
t
){
#if defined ZMQ_HAVE_WINDOWS
if
(
gettimeofday
(
&
t
->
time_now
,
NULL
)
<
0
){
perror
(
"d_timer_init()"
);}
// Get the high resolution counter's accuracy.
LARGE_INTEGER
ticksPerSecond
;
QueryPerformanceFrequency
(
&
ticksPerSecond
);
// What time is it?
LARGE_INTEGER
tick
;
if
(
!
QueryPerformanceCounter
(
&
tick
)
)
{
perror
(
"tm_init()"
);
}
// Seconds
t
->
time_now
.
tv_sec
=
(
long
)(
tick
.
QuadPart
/
ticksPerSecond
.
QuadPart
);
// Microseconds
t
->
time_now
.
tv_usec
=
(
long
)(
(
tick
.
QuadPart
-
t
->
time_now
.
tv_sec
*
ticksPerSecond
.
QuadPart
)
*
1000000
/
ticksPerSecond
.
QuadPart
);
#else
if
(
gettimeofday
(
&
t
->
time_now
,
NULL
)
<
0
){
perror
(
"tm_init()"
);}
#endif
t
->
time_was
=
t
->
time_now
;
t
->
time_was
=
t
->
time_now
;
}
}
...
@@ -54,9 +73,22 @@ void tm_init( US_TIMER *t){
...
@@ -54,9 +73,22 @@ void tm_init( US_TIMER *t){
float
tm_secs
(
US_TIMER
*
t
){
float
tm_secs
(
US_TIMER
*
t
){
register
float
seconds
;
register
float
seconds
;
#if defined ZMQ_HAVE_WINDOWS
if
(
gettimeofday
(
&
t
->
time_now
,
NULL
)
<
0
){
perror
(
"d_timer_init()"
);}
// Get the high resolution counter's accuracy.
LARGE_INTEGER
ticksPerSecond
;
QueryPerformanceFrequency
(
&
ticksPerSecond
);
// What time is it?
LARGE_INTEGER
tick
;
if
(
!
QueryPerformanceCounter
(
&
tick
)
)
{
perror
(
"tm_secs()"
);
}
// Seconds
t
->
time_now
.
tv_sec
=
(
long
)(
tick
.
QuadPart
/
ticksPerSecond
.
QuadPart
);
// Microseconds
t
->
time_now
.
tv_usec
=
(
long
)(
(
tick
.
QuadPart
-
t
->
time_now
.
tv_sec
*
ticksPerSecond
.
QuadPart
)
*
1000000
/
ticksPerSecond
.
QuadPart
);
#else
if
(
gettimeofday
(
&
t
->
time_now
,
NULL
)
<
0
){
perror
(
"tm_secs()"
);}
#endif
seconds
=
(
((
float
)(
t
->
time_now
.
tv_sec
-
t
->
time_was
.
tv_sec
))
+
seconds
=
(
((
float
)(
t
->
time_now
.
tv_sec
-
t
->
time_was
.
tv_sec
))
+
(((
float
)(
t
->
time_now
.
tv_usec
-
t
->
time_was
.
tv_usec
))
/
1000000.0
));
(((
float
)(
t
->
time_now
.
tv_usec
-
t
->
time_was
.
tv_usec
))
/
1000000.0
));
...
...
perf/remote_thr.cpp
View file @
5973b4c6
...
@@ -23,11 +23,9 @@
...
@@ -23,11 +23,9 @@
#include "../include/zmq_utils.h"
#include "../include/zmq_utils.h"
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <string.h>
#include <time.h>
#include <time.h>
#include <limits.h>
#include <limits.h>
#include <sys/time.h>
#include "platform.hpp"
#include "platform.hpp"
...
@@ -35,6 +33,8 @@
...
@@ -35,6 +33,8 @@
#include <windows.h>
#include <windows.h>
#include <process.h>
#include <process.h>
#else
#else
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>
#include <pthread.h>
#endif
#endif
...
@@ -61,11 +61,25 @@ struct US_TIMER{
...
@@ -61,11 +61,25 @@ struct US_TIMER{
/* Records the current timer state
/* Records the current timer state
*/
*/
void
tm_init
(
US_TIMER
*
t
){
void
tm_init
(
US_TIMER
*
t
){
#if defined ZMQ_HAVE_WINDOWS
if
(
gettimeofday
(
&
t
->
time_now
,
NULL
)
<
0
){
perror
(
"d_timer_init()"
);}
// Get the high resolution counter's accuracy.
LARGE_INTEGER
ticksPerSecond
;
QueryPerformanceFrequency
(
&
ticksPerSecond
);
t
->
time_was
=
t
->
time_now
;
// What time is it?
LARGE_INTEGER
tick
;
if
(
!
QueryPerformanceCounter
(
&
tick
)
)
{
perror
(
"tm_init()"
);
}
// Seconds
t
->
time_now
.
tv_sec
=
(
long
)(
tick
.
QuadPart
/
ticksPerSecond
.
QuadPart
);
// Microseconds
t
->
time_now
.
tv_usec
=
(
long
)(
(
tick
.
QuadPart
-
t
->
time_now
.
tv_sec
*
ticksPerSecond
.
QuadPart
)
*
1000000
/
ticksPerSecond
.
QuadPart
);
#else
if
(
gettimeofday
(
&
t
->
time_now
,
NULL
)
<
0
){
perror
(
"tm_init()"
);}
#endif
t
->
time_was
=
t
->
time_now
;
}
}
/* Returns the time passed in microsecond precision in seconds since last init
/* Returns the time passed in microsecond precision in seconds since last init
...
@@ -75,14 +89,28 @@ float tm_secs( US_TIMER *t){
...
@@ -75,14 +89,28 @@ float tm_secs( US_TIMER *t){
register
float
seconds
;
register
float
seconds
;
if
(
gettimeofday
(
&
t
->
time_now
,
NULL
)
<
0
){
perror
(
"d_timer_init()"
);}
#if defined ZMQ_HAVE_WINDOWS
// Get the high resolution counter's accuracy.
LARGE_INTEGER
ticksPerSecond
;
QueryPerformanceFrequency
(
&
ticksPerSecond
);
// What time is it?
LARGE_INTEGER
tick
;
if
(
!
QueryPerformanceCounter
(
&
tick
)
)
{
perror
(
"tm_secs()"
);
}
// Seconds
t
->
time_now
.
tv_sec
=
(
long
)(
tick
.
QuadPart
/
ticksPerSecond
.
QuadPart
);
// Microseconds
t
->
time_now
.
tv_usec
=
(
long
)(
(
tick
.
QuadPart
-
t
->
time_now
.
tv_sec
*
ticksPerSecond
.
QuadPart
)
*
1000000
/
ticksPerSecond
.
QuadPart
);
#else
if
(
gettimeofday
(
&
t
->
time_now
,
NULL
)
<
0
){
perror
(
"tm_secs()"
);}
#endif
seconds
=
(
((
float
)(
t
->
time_now
.
tv_sec
-
t
->
time_was
.
tv_sec
))
+
seconds
=
(
((
float
)(
t
->
time_now
.
tv_sec
-
t
->
time_was
.
tv_sec
))
+
(((
float
)(
t
->
time_now
.
tv_usec
-
t
->
time_was
.
tv_usec
))
/
1000000.0
));
(((
float
)(
t
->
time_now
.
tv_usec
-
t
->
time_was
.
tv_usec
))
/
1000000.0
));
t
->
time_was
=
t
->
time_now
;
t
->
time_was
=
t
->
time_now
;
return
(
seconds
)
;
return
seconds
;
}
}
void
my_free
(
void
*
data
,
void
*
hint
)
void
my_free
(
void
*
data
,
void
*
hint
)
...
...
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