示例#1
0
func dbConnect(name string) *dbm.DB {
	if checkDbExist(name) != true {
		db, err := dbm.Create(name, o)
		if err != nil {
			fmt.Printf("Error: dbm can't create\n")
			panic(err)
		} else {
			return db
		}
	} else {
		db, err := dbm.Open(name, o)
		if err != nil {
			fmt.Printf("Error: dbm can't open\n")
			panic(err)
		} else {
			return db
		}
	}
	return nil
}
示例#2
0
func fillseq(acid int) {
	dbname := os.Args[0] + ".db"
	db, err := dbm.Create(dbname, &dbm.Options{ACID: acid, GracePeriod: time.Second})
	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		os.Remove(dbname)
	}()

	a, err := db.Array("")
	if err != nil {
		log.Println(err)
		return
	}

	t0 := time.Now()
	for i := 0; i < N; i++ {
		if err = a.Set(value100, i); err != nil {
			log.Println(err)
			return
		}
	}
	if err := db.Close(); err != nil {
		log.Println(err)
		return
	}

	d := time.Since(t0)
	fi, err := os.Stat(dbname)
	if err != nil {
		log.Println(err)
		return
	}

	secs := float64(d/time.Nanosecond) / float64(time.Second)
	sz := fi.Size()
	fmt.Printf("fillseq      :%19v/op;%7.1f MB/s (%g secs, %d bytes)\n", d/N, float64(sz)/secs/1e6, secs, sz)
}