Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
91a59e03
Commit
91a59e03
authored
Sep 07, 2016
by
antirez
Browse files
dict.c benchmark.
parent
57a0db94
Changes
2
Show whitespace changes
Inline
Side-by-side
src/Makefile
View file @
91a59e03
...
@@ -203,6 +203,9 @@ $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
...
@@ -203,6 +203,9 @@ $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
$(REDIS_CHECK_AOF_NAME)
:
$(REDIS_CHECK_AOF_OBJ)
$(REDIS_CHECK_AOF_NAME)
:
$(REDIS_CHECK_AOF_OBJ)
$(REDIS_LD)
-o
$@
$^
$(FINAL_LIBS)
$(REDIS_LD)
-o
$@
$^
$(FINAL_LIBS)
dict-benchmark
:
dict.c zmalloc.c sds.c
$(REDIS_CC)
$(FINAL_CFLAGS)
dict.c zmalloc.c sds.c
-D
DICT_BENCHMARK_MAIN
-o
dict-benchmark
# Because the jemalloc.h header is generated as a part of the jemalloc build,
# Because the jemalloc.h header is generated as a part of the jemalloc build,
# building it should complete before building any other object. Instead of
# building it should complete before building any other object. Instead of
# depending on a single artifact, build all dependencies first.
# depending on a single artifact, build all dependencies first.
...
@@ -210,7 +213,7 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
...
@@ -210,7 +213,7 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_CHECK_AOF_OBJ)
$(REDIS_CC)
-c
$<
$(REDIS_CC)
-c
$<
clean
:
clean
:
rm
-rf
$(REDIS_SERVER_NAME)
$(REDIS_SENTINEL_NAME)
$(REDIS_CLI_NAME)
$(REDIS_BENCHMARK_NAME)
$(REDIS_CHECK_RDB_NAME)
$(REDIS_CHECK_AOF_NAME)
*
.o
*
.gcda
*
.gcno
*
.gcov redis.info lcov-html Makefile.dep
rm
-rf
$(REDIS_SERVER_NAME)
$(REDIS_SENTINEL_NAME)
$(REDIS_CLI_NAME)
$(REDIS_BENCHMARK_NAME)
$(REDIS_CHECK_RDB_NAME)
$(REDIS_CHECK_AOF_NAME)
*
.o
*
.gcda
*
.gcno
*
.gcov redis.info lcov-html Makefile.dep
dict-benchmark
.PHONY
:
clean
.PHONY
:
clean
...
...
src/dict.c
View file @
91a59e03
...
@@ -45,7 +45,11 @@
...
@@ -45,7 +45,11 @@
#include "dict.h"
#include "dict.h"
#include "zmalloc.h"
#include "zmalloc.h"
#ifndef DICT_BENCHMARK_MAIN
#include "redisassert.h"
#include "redisassert.h"
#else
#include <assert.h>
#endif
/* Using dictEnableResize() / dictDisableResize() we make possible to
/* Using dictEnableResize() / dictDisableResize() we make possible to
* enable/disable resizing of the hash table as needed. This is very important
* enable/disable resizing of the hash table as needed. This is very important
...
@@ -1083,3 +1087,55 @@ void dictGetStats(char *buf, size_t bufsize, dict *d) {
...
@@ -1083,3 +1087,55 @@ void dictGetStats(char *buf, size_t bufsize, dict *d) {
/* Make sure there is a NULL term at the end. */
/* Make sure there is a NULL term at the end. */
if
(
orig_bufsize
)
orig_buf
[
orig_bufsize
-
1
]
=
'\0'
;
if
(
orig_bufsize
)
orig_buf
[
orig_bufsize
-
1
]
=
'\0'
;
}
}
/* ------------------------------- Benchmark ---------------------------------*/
#ifdef DICT_BENCHMARK_MAIN
#include "sds.h"
unsigned
int
hashCallback
(
const
void
*
key
)
{
return
dictGenHashFunction
((
unsigned
char
*
)
key
,
sdslen
((
char
*
)
key
));
}
int
compareCallback
(
void
*
privdata
,
const
void
*
key1
,
const
void
*
key2
)
{
int
l1
,
l2
;
DICT_NOTUSED
(
privdata
);
l1
=
sdslen
((
sds
)
key1
);
l2
=
sdslen
((
sds
)
key2
);
if
(
l1
!=
l2
)
return
0
;
return
memcmp
(
key1
,
key2
,
l1
)
==
0
;
}
void
freeCallback
(
void
*
privdata
,
void
*
val
)
{
DICT_NOTUSED
(
privdata
);
sdsfree
(
val
);
}
dictType
BenchmarkDictType
=
{
hashCallback
,
NULL
,
NULL
,
compareCallback
,
freeCallback
,
NULL
};
int
main
(
void
)
{
long
j
;
long
hits
=
0
,
misses
=
0
;
long
long
start
,
elapsed
;
dict
*
dict
=
dictCreate
(
&
BenchmarkDictType
,
NULL
);
start
=
timeInMilliseconds
();
for
(
j
=
0
;
j
<
5000000
;
j
++
)
{
int
retval
=
dictAdd
(
dict
,
sdsfromlonglong
(
j
),(
void
*
)
j
);
assert
(
retval
==
DICT_OK
);
}
elapsed
=
timeInMilliseconds
()
-
start
;
printf
(
"Inserting 5M items: %lld ms
\n
"
,
elapsed
);
assert
(
dictSize
(
dict
)
==
5000000
);
}
#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