Last active
July 12, 2021 15:21
-
-
Save maxim-ge/fc3f447256e056cfcc387594679f8b7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"strconv" | |
"time" | |
bolt "github.com/coreos/bbolt" | |
) | |
const NRECS = 1000 | |
/* | |
Put NRECS kv pairs | |
*/ | |
func main() { | |
db, err := bolt.Open("speed.db", 0600, nil) | |
if err != nil { | |
log.Panicln("Oops:", err) | |
} | |
defer db.Close() | |
db.Update(func(tx *bolt.Tx) error { | |
_, err := tx.CreateBucketIfNotExists([]byte("MyBucket")) | |
if err != nil { | |
log.Panicln("Oops:", err) | |
} | |
return nil | |
}) | |
t1 := time.Now() | |
for i := 0; i < NRECS; i++ { | |
db.Update(func(tx *bolt.Tx) error { | |
b := tx.Bucket([]byte("MyBucket")) | |
err = b.Put([]byte(strconv.Itoa(i)), []byte("key"+strconv.Itoa(i))) | |
if err != nil { | |
log.Panicln("Oops:", err) | |
} | |
return nil | |
}) | |
if i%20 == 0 { | |
fmt.Println(i) | |
} | |
} | |
spent := time.Now().Sub(t1).Seconds() | |
fmt.Println("Spent:", spent, ", per sec: ", NRECS/spent) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Windows 7, HDD: Spent: 5.1342937 , per sec: 19.476875660619104