Skip to content

Instantly share code, notes, and snippets.

@maxim-ge
Last active July 12, 2021 15:21
Show Gist options
  • Save maxim-ge/fc3f447256e056cfcc387594679f8b7e to your computer and use it in GitHub Desktop.
Save maxim-ge/fc3f447256e056cfcc387594679f8b7e to your computer and use it in GitHub Desktop.
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)
}
@maxim-ge
Copy link
Author

maxim-ge commented Apr 6, 2018

Windows 7, HDD: Spent: 5.1342937 , per sec: 19.476875660619104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment