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
8793dd42
Commit
8793dd42
authored
Feb 22, 2016
by
William Ahern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more benchmark script work
parent
44841540
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
34 deletions
+93
-34
Makefile
Makefile
+1
-1
bench-add.lua
bench-add.lua
+17
-11
bench-aux.lua
bench-aux.lua
+10
-0
bench-del.lua
bench-del.lua
+14
-6
bench-expire.lua
bench-expire.lua
+18
-6
bench.c
bench.c
+33
-10
No files found.
Makefile
View file @
8793dd42
all
:
bench.so bench-wheel.so bench-heap.so
all
:
bench.so bench-wheel.so bench-heap.so
bench-llrb.so
WHEEL_BIT
=
6
WHEEL_NUM
=
4
...
...
bench-add.lua
100644 → 100755
View file @
8793dd42
...
...
@@ -3,22 +3,28 @@
local
bench
=
require
"bench"
local
aux
=
require
"bench-aux"
local
lib
=
...
or
"bench-wheel.so"
local
limit
=
1000000
local
step
=
limit
/
100
local
lib
=
...
or
aux
.
optenv
(
"BENCH_L"
,
"bench-wheel.so"
)
local
limit
=
tonumber
(
aux
.
optenv
(
"BENCH_N"
,
1000000
))
local
step
=
tonumber
(
aux
.
optenv
(
"BENCH_S"
,
limit
/
100
))
local
exp_step
=
tonumber
(
aux
.
optenv
(
"BENCH_E"
,
1
.
0
))
local
verbose
=
aux
.
toboolean
(
os.getenv
(
"BENCH_V"
,
false
))
local
B
=
bench
.
new
(
lib
,
count
)
B
:
fill
(
limit
)
local
n
=
limit
local
B
=
bench
.
new
(
lib
,
count
,
nil
,
verbose
)
local
fill_count
,
fill_last
=
B
:
fill
(
limit
)
for
i
=
0
,
limit
,
step
do
local
exp_elapsed
,
fill_elapsed
,
fill_rate
-- expire all timeouts
local
expire_t
=
aux
.
time
(
B
.
expire
,
B
,
n
)
--exp_elapsed = aux.time(B.expire, B, fill_count, fill_last * exp_step)
exp_elapsed
=
aux
.
time
(
B
.
del
,
B
,
0
,
fill_count
)
assert
(
B
:
empty
())
-- add i timeouts
local
fill_t
=
aux
.
time
(
B
.
fill
,
B
,
i
)
n
=
i
fill_elapsed
,
fill_count
,
fill_last
=
aux
.
time
(
B
.
fill
,
B
,
i
)
assert
(
fill_count
==
i
)
fill_rate
=
fill_elapsed
>
0
and
(
fill_count
/
fill_elapsed
)
or
0
aux
.
say
(
"%i\t%f\t(%f)"
,
i
,
fill_t
,
expire_t
)
local
fmt
=
verbose
and
"%d\t%f\t(%d/s)\t(exp:%f)"
or
"%d\t%f"
aux
.
say
(
fmt
,
i
,
fill_elapsed
,
fill_rate
,
exp_elapsed
)
end
bench-aux.lua
View file @
8793dd42
...
...
@@ -17,4 +17,14 @@ function aux.say(...)
print
(
string.format
(
...
))
end
function
aux
.
toboolean
(
s
)
return
tostring
(
s
):
match
(
"^[1TtYy]"
)
and
true
or
false
end
function
aux
.
optenv
(
k
,
def
)
local
s
=
os.getenv
(
k
)
return
(
s
and
#
s
>
0
and
s
)
or
def
end
return
aux
bench-del.lua
100644 → 100755
View file @
8793dd42
...
...
@@ -3,15 +3,23 @@
local
bench
=
require
"bench"
local
aux
=
require
"bench-aux"
local
lib
=
...
or
"bench-wheel.so"
local
limit
=
1000000
local
step
=
limit
/
100
local
lib
=
...
or
aux
.
optenv
(
"BENCH_L"
,
"bench-wheel.so"
)
local
limit
=
tonumber
(
aux
.
optenv
(
"BENCH_N"
,
1000000
))
local
step
=
tonumber
(
aux
.
optenv
(
"BENCH_S"
,
limit
/
100
))
local
verbose
=
aux
.
toboolean
(
os.getenv
(
"BENCH_V"
,
false
))
local
B
=
bench
.
new
(
lib
,
count
)
for
i
=
0
,
limit
,
step
do
local
fill_t
=
aux
.
time
(
B
.
fill
,
B
,
i
,
60
*
1000000
)
local
del_t
=
aux
.
time
(
B
.
del
,
B
,
0
,
i
)
-- add i timeouts
local
fill_elapsed
,
fill_count
=
aux
.
time
(
B
.
fill
,
B
,
i
,
60
*
1000000
)
assert
(
i
==
fill_count
)
aux
.
say
(
"%i\t%f\t(%f)"
,
i
,
del_t
,
fill_t
)
--- delete i timeouts
local
del_elapsed
=
aux
.
time
(
B
.
del
,
B
,
0
,
fill_count
)
assert
(
B
:
empty
())
local
del_rate
=
i
>
0
and
i
/
del_elapsed
or
0
local
fmt
=
verbose
and
"%d\t%f\t(%d/s)\t(fill:%f)"
or
"%d\t%f"
aux
.
say
(
fmt
,
i
,
del_elapsed
,
del_rate
,
fill_elapsed
)
end
bench-expire.lua
100644 → 100755
View file @
8793dd42
...
...
@@ -3,15 +3,27 @@
local
bench
=
require
"bench"
local
aux
=
require
"bench-aux"
local
lib
=
...
or
"bench-wheel.so"
local
limit
=
1000000
local
step
=
limit
/
100
local
lib
=
...
or
aux
.
optenv
(
"BENCH_L"
,
"bench-wheel.so"
)
local
limit
=
tonumber
(
aux
.
optenv
(
"BENCH_N"
,
1000000
))
local
step
=
tonumber
(
aux
.
optenv
(
"BENCH_S"
,
limit
/
100
))
-- expire 1/1000 * #timeouts per clock update
local
exp_step
=
tonumber
(
aux
.
optenv
(
"BENCH_E"
,
0
.
0001
))
local
verbose
=
aux
.
toboolean
(
os.getenv
(
"BENCH_V"
,
false
))
local
B
=
require
"bench"
.
new
(
lib
,
count
)
for
i
=
0
,
limit
,
step
do
local
fill_t
=
aux
.
time
(
B
.
fill
,
B
,
i
)
local
expire_t
=
aux
.
time
(
B
.
expire
,
B
,
i
)
--, 60000000
)
-- add i timeouts
local
fill_elapsed
,
fill_count
,
fill_last
=
aux
.
time
(
B
.
fill
,
B
,
i
)
aux
.
say
(
"%i\t%f\t(%f)"
,
i
,
expire_t
,
fill_t
)
-- expire timeouts by iteratively updating clock. exp_step is the
-- approximate number of timeouts (as a fraction of the total number
-- of timeouts) that will expire per update.
local
exp_elapsed
,
exp_count
=
aux
.
time
(
B
.
expire
,
B
,
fill_count
,
fill_last
*
exp_step
)
assert
(
exp_count
==
i
)
assert
(
B
:
empty
())
local
exp_rate
=
i
>
0
and
i
/
exp_elapsed
or
0
local
fmt
=
verbose
and
"%d\t%f\t(%d/s)\t(fill:%f)"
or
"%d\t%f"
aux
.
say
(
fmt
,
i
,
exp_elapsed
,
exp_rate
,
fill_elapsed
)
end
bench.c
View file @
8793dd42
...
...
@@ -16,12 +16,16 @@
#include "timeout.h"
#include "bench.h"
#ifndef MAX
#define MAX(a, b) (((a) > (b))? (a) : (b))
#endif
struct
bench
{
const
char
*
path
;
void
*
solib
;
size_t
count
;
timeout_t
maximum
;
timeout_t
timeout_max
;
int
verbose
;
void
*
state
;
...
...
@@ -64,7 +68,7 @@ static int bench_clock(lua_State *L) {
static
int
bench_new
(
lua_State
*
L
)
{
const
char
*
path
=
luaL_checkstring
(
L
,
1
);
size_t
count
=
luaL_optlong
(
L
,
2
,
1000000
);
timeout_t
tmax
=
luaL_optlong
(
L
,
3
,
300
*
1000000L
);
timeout_t
t
imeout_
max
=
luaL_optlong
(
L
,
3
,
300
*
1000000L
);
int
verbose
=
(
lua_isnone
(
L
,
4
))
?
0
:
lua_toboolean
(
L
,
4
);
struct
bench
*
B
;
struct
benchops
*
ops
;
...
...
@@ -76,7 +80,7 @@ static int bench_new(lua_State *L) {
lua_setmetatable
(
L
,
-
2
);
B
->
count
=
count
;
B
->
maximum
=
t
max
;
B
->
timeout_max
=
timeout_
max
;
B
->
verbose
=
verbose
;
if
(
!
(
B
->
timeout
=
calloc
(
count
,
sizeof
*
B
->
timeout
)))
...
...
@@ -101,7 +105,7 @@ static int bench_add(lua_State *L) {
timeout_t
t
;
i
=
(
lua_isnoneornil
(
L
,
2
))
?
random
()
%
B
->
count
:
(
unsigned
)
luaL_checklong
(
L
,
2
);
t
=
(
lua_isnoneornil
(
L
,
3
))
?
random
()
%
B
->
maximum
:
(
unsigned
)
luaL_checklong
(
L
,
3
);
t
=
(
lua_isnoneornil
(
L
,
3
))
?
random
()
%
B
->
timeout_max
:
(
unsigned
)
luaL_checklong
(
L
,
3
);
B
->
ops
.
add
(
B
->
state
,
&
B
->
timeout
[
i
],
t
);
...
...
@@ -126,20 +130,27 @@ static int bench_del(lua_State *L) {
static
int
bench_fill
(
lua_State
*
L
)
{
struct
bench
*
B
=
lua_touserdata
(
L
,
1
);
size_t
count
=
luaL_optlong
(
L
,
2
,
B
->
count
);
long
timeout
=
luaL_optlong
(
L
,
3
,
-
1
)
;
long
timeout
_inc
=
luaL_optlong
(
L
,
3
,
-
1
),
timeout_max
=
0
,
timeout
;
size_t
i
;
if
(
timeout
<
0
)
{
if
(
timeout
_inc
<
0
)
{
for
(
i
=
0
;
i
<
count
;
i
++
)
{
B
->
ops
.
add
(
B
->
state
,
&
B
->
timeout
[
i
],
random
()
%
B
->
maximum
);
timeout
=
random
()
%
B
->
timeout_max
;
B
->
ops
.
add
(
B
->
state
,
&
B
->
timeout
[
i
],
timeout
);
timeout_max
=
MAX
(
timeout
,
timeout_max
);
}
}
else
{
for
(
i
=
0
;
i
<
count
;
i
++
)
{
B
->
ops
.
add
(
B
->
state
,
&
B
->
timeout
[
i
],
timeout
+
i
);
timeout
=
timeout_inc
+
i
;
B
->
ops
.
add
(
B
->
state
,
&
B
->
timeout
[
i
],
timeout_inc
+
i
);
timeout_max
=
MAX
(
timeout
,
timeout_max
);
}
}
return
0
;
lua_pushinteger
(
L
,
(
lua_Integer
)
count
);
lua_pushinteger
(
L
,
(
lua_Integer
)
timeout_max
);
return
2
;
}
/* bench_fill() */
...
...
@@ -157,10 +168,21 @@ static int bench_expire(lua_State *L) {
i
++
;
}
return
0
;
lua_pushinteger
(
L
,
(
lua_Integer
)
i
);
return
1
;
}
/* bench_expire() */
static
int
bench_empty
(
lua_State
*
L
)
{
struct
bench
*
B
=
lua_touserdata
(
L
,
1
);
lua_pushboolean
(
L
,
B
->
ops
.
empty
(
B
->
state
));
return
1
;
}
/* bench_empty() */
static
int
bench__gc
(
lua_State
*
L
)
{
struct
bench
*
B
=
lua_touserdata
(
L
,
1
);
...
...
@@ -178,6 +200,7 @@ static const luaL_Reg bench_methods[] = {
{
"del"
,
&
bench_del
},
{
"fill"
,
&
bench_fill
},
{
"expire"
,
&
bench_expire
},
{
"empty"
,
&
bench_empty
},
{
"close"
,
&
bench__gc
},
{
NULL
,
NULL
}
};
...
...
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