Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
ed6a4517
Commit
ed6a4517
authored
Sep 07, 2016
by
antirez
Browse files
dict.c benchmark improvements.
parent
1074f736
Changes
1
Show whitespace changes
Inline
Side-by-side
src/dict.c
View file @
ed6a4517
...
...
@@ -1123,10 +1123,15 @@ dictType BenchmarkDictType = {
NULL
};
#define start_benchmark() start = timeInMilliseconds()
#define end_benchmark(msg) do { \
elapsed = timeInMilliseconds()-start; \
printf(msg ": %ld items in %lld ms\n", count, elapsed); \
} while(0);
/* dict-benchmark [count] */
int
main
(
int
argc
,
char
**
argv
)
{
long
j
;
long
hits
=
0
,
misses
=
0
;
long
long
start
,
elapsed
;
dict
*
dict
=
dictCreate
(
&
BenchmarkDictType
,
NULL
);
long
count
=
0
;
...
...
@@ -1137,13 +1142,31 @@ int main(int argc, char **argv) {
count
=
5000000
;
}
start
=
timeInMilliseconds
();
start
_benchmark
();
for
(
j
=
0
;
j
<
count
;
j
++
)
{
int
retval
=
dictAdd
(
dict
,
sdsfromlonglong
(
j
),(
void
*
)
j
);
assert
(
retval
==
DICT_OK
);
}
elapsed
=
timeInMilliseconds
()
-
start
;
printf
(
"Inserting 5M items: %lld ms
\n
"
,
elapsed
);
end_benchmark
(
"Inserting"
);
assert
((
long
)
dictSize
(
dict
)
==
count
);
start_benchmark
();
for
(
j
=
0
;
j
<
count
;
j
++
)
{
sds
key
=
sdsfromlonglong
(
rand
()
%
count
);
dictEntry
*
de
=
dictFind
(
dict
,
key
);
assert
(
de
!=
NULL
);
sdsfree
(
key
);
}
end_benchmark
(
"Accessing existing"
);
start_benchmark
();
for
(
j
=
0
;
j
<
count
;
j
++
)
{
sds
key
=
sdsfromlonglong
(
rand
()
%
count
);
key
[
0
]
=
'X'
;
dictEntry
*
de
=
dictFind
(
dict
,
key
);
assert
(
de
==
NULL
);
sdsfree
(
key
);
}
end_benchmark
(
"Accessing missing"
);
}
#endif
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