remove crand for benchmark

This commit is contained in:
siddontang 2014-10-24 16:39:06 +08:00
parent e0124cb64a
commit 5cfffba6e1
2 changed files with 5 additions and 11 deletions

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
crand "crypto/rand"
"flag" "flag"
"fmt" "fmt"
"github.com/siddontang/ledisdb/client/go/ledis" "github.com/siddontang/ledisdb/client/go/ledis"
@ -42,7 +41,7 @@ func bench(cmd string, f func()) {
t1 := time.Now() t1 := time.Now()
for i := 0; i < *clients; i++ { for i := 0; i < *clients; i++ {
go func() { go func() {
for i := 0; i < loop; i++ { for j := 0; j < loop; j++ {
f() f()
} }
wg.Done() wg.Done()
@ -64,7 +63,6 @@ var kvDelBase int64 = 0
func benchSet() { func benchSet() {
f := func() { f := func() {
value := make([]byte, *valueSize) value := make([]byte, *valueSize)
crand.Read(value)
n := atomic.AddInt64(&kvSetBase, 1) n := atomic.AddInt64(&kvSetBase, 1)
waitBench("set", n, value) waitBench("set", n, value)
} }
@ -102,7 +100,6 @@ func benchDel() {
func benchPushList() { func benchPushList() {
f := func() { f := func() {
value := make([]byte, 100) value := make([]byte, 100)
crand.Read(value)
waitBench("rpush", "mytestlist", value) waitBench("rpush", "mytestlist", value)
} }
@ -149,7 +146,6 @@ var hashDelBase int64 = 0
func benchHset() { func benchHset() {
f := func() { f := func() {
value := make([]byte, 100) value := make([]byte, 100)
crand.Read(value)
n := atomic.AddInt64(&hashSetBase, 1) n := atomic.AddInt64(&hashSetBase, 1)
waitBench("hset", "myhashkey", n, value) waitBench("hset", "myhashkey", n, value)
@ -192,7 +188,6 @@ var zsetIncrBase int64 = 0
func benchZAdd() { func benchZAdd() {
f := func() { f := func() {
member := make([]byte, 16) member := make([]byte, 16)
crand.Read(member)
n := atomic.AddInt64(&zsetAddBase, 1) n := atomic.AddInt64(&zsetAddBase, 1)
waitBench("zadd", "myzsetkey", n, member) waitBench("zadd", "myzsetkey", n, member)
} }

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
crand "crypto/rand"
"flag" "flag"
"fmt" "fmt"
"github.com/siddontang/go/num" "github.com/siddontang/go/num"
@ -35,7 +34,7 @@ func bench(cmd string, f func()) {
t1 := time.Now() t1 := time.Now()
for i := 0; i < *clients; i++ { for i := 0; i < *clients; i++ {
go func() { go func() {
for i := 0; i < loop; i++ { for j := 0; j < loop; j++ {
f() f()
} }
wg.Done() wg.Done()
@ -46,8 +45,9 @@ func bench(cmd string, f func()) {
t2 := time.Now() t2 := time.Now()
fmt.Printf("%s: %0.2f op/s, %0.2fmb/s\n", cmd, (float64(*number) / t2.Sub(t1).Seconds()), d := t2.Sub(t1)
float64(*valueSize*(*number))/(1024.0*1024.0*(t2.Sub(t1).Seconds()))) fmt.Printf("%s: %0.3f micros/op, %0.2fmb/s\n", cmd, float64(d.Nanoseconds()/1e3)/float64(*number),
float64((*valueSize+16)*(*number))/(1024.0*1024.0*(d.Seconds())))
} }
var kvSetBase int64 = 0 var kvSetBase int64 = 0
@ -56,7 +56,6 @@ var kvGetBase int64 = 0
func benchSet() { func benchSet() {
f := func() { f := func() {
value := make([]byte, *valueSize) value := make([]byte, *valueSize)
crand.Read(value)
n := atomic.AddInt64(&kvSetBase, 1) n := atomic.AddInt64(&kvSetBase, 1)
db.Put(num.Int64ToBytes(n), value) db.Put(num.Int64ToBytes(n), value)