Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
timeout.c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
timeout.c
Commits
ff505515
Commit
ff505515
authored
Feb 02, 2014
by
william
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use system monotonic time instead of clock()
parent
a605dc78
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
Makefile
Makefile
+6
-1
bench.c
bench.c
+27
-1
No files found.
Makefile
View file @
ff505515
...
@@ -34,8 +34,13 @@ else
...
@@ -34,8 +34,13 @@ else
SOFLAGS
=
-shared
SOFLAGS
=
-shared
endif
endif
ifeq
($(shell -uname -s), Linux)
LIBS
=
-lrt
endif
bench.so
:
bench.c
bench.so
:
bench.c
$(CC)
-o
$@
$<
$(CPPFLAGS)
-DLUA_COMPAT_ALL
$(CFLAGS)
-Wno-unused-function
$(SOFLAGS)
$(CC)
-o
$@
$<
$(CPPFLAGS)
-DLUA_COMPAT_ALL
$(CFLAGS)
-Wno-unused-function
$(SOFLAGS)
$(LIBS)
bench-wheel8.so
:
CPPFLAGS+=-DWHEEL_BIT=3 -DWHEEL_NUM=$(WHEEL_NUM)
bench-wheel8.so
:
CPPFLAGS+=-DWHEEL_BIT=3 -DWHEEL_NUM=$(WHEEL_NUM)
...
...
bench.c
View file @
ff505515
...
@@ -5,6 +5,10 @@
...
@@ -5,6 +5,10 @@
#include <unistd.h>
#include <unistd.h>
#include <dlfcn.h>
#include <dlfcn.h>
#if __APPLE__
#include <mach/mach_time.h>
#endif
#include <lua.h>
#include <lua.h>
#include <lualib.h>
#include <lualib.h>
#include <lauxlib.h>
#include <lauxlib.h>
...
@@ -24,11 +28,29 @@ struct bench {
...
@@ -24,11 +28,29 @@ struct bench {
struct
timeout
*
timeout
;
struct
timeout
*
timeout
;
struct
benchops
ops
;
struct
benchops
ops
;
timeout_t
curtime
;
timeout_t
curtime
;
#if __APPLE__
mach_timebase_info_data_t
timebase
;
#endif
};
/* struct bench */
};
/* struct bench */
static
int
bench_clock
(
lua_State
*
L
)
{
static
int
bench_clock
(
lua_State
*
L
)
{
lua_pushnumber
(
L
,
(
double
)
clock
()
/
CLOCKS_PER_SEC
);
#if __APPLE__
struct
bench
*
B
=
lua_touserdata
(
L
,
1
);
unsigned
long
long
abt
;
abt
=
mach_absolute_time
();
abt
=
abt
*
B
->
timebase
.
numer
/
B
->
timebase
.
denom
;
lua_pushnumber
(
L
,
(
double
)
abt
/
1000000000L
);
#else
struct
timespec
ts
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
lua_pushnumber
(
L
,
(
double
)
ts
.
tv_sec
+
((
double
)
ts
.
tv_nsec
/
1000000000L
));
#endif
return
1
;
return
1
;
}
/* bench_clock() */
}
/* bench_clock() */
...
@@ -45,6 +67,10 @@ static int bench_new(lua_State *L) {
...
@@ -45,6 +67,10 @@ static int bench_new(lua_State *L) {
B
=
lua_newuserdata
(
L
,
sizeof
*
B
);
B
=
lua_newuserdata
(
L
,
sizeof
*
B
);
memset
(
B
,
0
,
sizeof
*
B
);
memset
(
B
,
0
,
sizeof
*
B
);
#if __APPLE__
mach_timebase_info
(
&
B
->
timebase
);
#endif
luaL_getmetatable
(
L
,
"BENCH*"
);
luaL_getmetatable
(
L
,
"BENCH*"
);
lua_setmetatable
(
L
,
-
2
);
lua_setmetatable
(
L
,
-
2
);
...
...
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