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
hiredis
Commits
66036d11
Commit
66036d11
authored
Sep 19, 2010
by
Pieter Noordhuis
Browse files
Add speed tests
parent
e7aa0b4b
Changes
1
Show whitespace changes
Inline
Side-by-side
test.c
View file @
66036d11
...
@@ -2,15 +2,23 @@
...
@@ -2,15 +2,23 @@
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <strings.h>
#include <strings.h>
#include <sys/time.h>
#include "hiredis.h"
#include "hiredis.h"
/* The following line is our testing "framework" :) */
/* The following line is our testing "framework" :) */
#define test_cond(_c) if(_c) printf("PASSED\n"); else {printf("FAILED\n"); fails++;}
#define test_cond(_c) if(_c) printf("PASSED\n"); else {printf("FAILED\n"); fails++;}
long
long
usec
(
void
)
{
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
return
(((
long
long
)
tv
.
tv_sec
)
*
1000000
)
+
tv
.
tv_usec
;
}
int
main
(
void
)
{
int
main
(
void
)
{
int
fd
;
int
fd
;
int
fails
=
0
;
int
i
,
fails
=
0
;
long
long
t1
,
t2
;
redisReply
*
reply
;
redisReply
*
reply
;
reply
=
redisConnect
(
&
fd
,
"127.0.0.1"
,
6379
);
reply
=
redisConnect
(
&
fd
,
"127.0.0.1"
,
6379
);
...
@@ -91,15 +99,31 @@ int main(void) {
...
@@ -91,15 +99,31 @@ int main(void) {
!
memcmp
(
reply
->
element
[
1
]
->
reply
,
"foo"
,
3
))
!
memcmp
(
reply
->
element
[
1
]
->
reply
,
"foo"
,
3
))
freeReplyObject
(
reply
);
freeReplyObject
(
reply
);
/* Clean DB 9 */
reply
=
redisCommand
(
fd
,
"FLUSHDB"
);
freeReplyObject
(
reply
);
if
(
fails
==
0
)
{
if
(
fails
==
0
)
{
printf
(
"ALL TESTS PASSED
\n
"
);
printf
(
"ALL TESTS PASSED
\n
"
);
}
else
{
}
else
{
printf
(
"*** %d TESTS FAILED ***
\n
"
,
fails
);
printf
(
"*** %d TESTS FAILED ***
\n
"
,
fails
);
}
}
printf
(
"
\n
Speed tests:
\n
"
);
for
(
i
=
0
;
i
<
500
;
i
++
)
freeReplyObject
(
redisCommand
(
fd
,
"LPUSH mylist foo"
));
t1
=
usec
();
for
(
i
=
0
;
i
<
1000
;
i
++
)
freeReplyObject
(
redisCommand
(
fd
,
"PING"
));
t2
=
usec
();
printf
(
"(1000x PING: %.2fs)
\n
"
,
(
t2
-
t1
)
/
1000000
.
0
);
t1
=
usec
();
for
(
i
=
0
;
i
<
1000
;
i
++
)
freeReplyObject
(
redisCommand
(
fd
,
"LRANGE mylist 0 499"
));
t2
=
usec
();
printf
(
"(1000x LRANGE with 500 elements: %.2fs)
\n
"
,
(
t2
-
t1
)
/
1000000
.
0
);
/* Clean DB 9 */
reply
=
redisCommand
(
fd
,
"FLUSHDB"
);
freeReplyObject
(
reply
);
return
0
;
return
0
;
}
}
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