func execute(method func(), t int) int64 { b := utee.Tick() for i := 0; i < t; i++ { method() } b = utee.Tick() - b return b }
func main() { err := os.MkdirAll("./gldb", 0777) utee.Chk(err) db, err := leveldb.OpenFile("./gldb", nil) utee.Chk(err) defer db.Close() err = db.Put([]byte("key"), []byte("value"), nil) utee.Chk(err) data, err := db.Get([]byte("key"), nil) utee.Chk(err) log.Println("@data:", string(data)) iter := db.NewIterator(nil, nil) i := 0 for iter.Next() { key := iter.Key() value := iter.Value() log.Println("@key:", string(key), "@value:", string(value)) i++ } log.Println("read @i:", i) iter.Release() err = iter.Error() err = db.Delete([]byte("key"), nil) utee.Chk(err) log.Println("热身完毕") st := utee.Tick() for i := 0; i < 10*10000; i++ { b, _ := json.Marshal(Test{Name: "figo", Tp: "android", Count: 1024}) db.Put([]byte(fmt.Sprint("test", i)), b, nil) } writeCost := utee.Tick() - st st = utee.Tick() iter = db.NewIterator(nil, nil) for iter.Next() { key := iter.Key() value := iter.Value() log.Println("@key:", string(key), "@value:", string(value)) err = db.Delete([]byte("key"), nil) utee.Chk(err) } log.Println("100,0000 read cost ", (utee.Tick() - st), "m second") log.Println("100,0000 write cost ", writeCost, "m second") iter.Release() if err := iter.Error(); err != nil { log.Println("iter @err:", err) } log.Println("finish") }
func main() { log.Println("hello") mg := connect("192.168.56.101/figoTest") cp := mg.Copy() defer cp.Close() apps := map[string]string{} apps["com.test.com"] = "特斯特" apps["com.cool.me"] = "酷儿" apps["com.mi.me"] = "米密" m := &MapTest{ Id: bson.NewObjectId(), Dvid: uuid.NewUUID().String(), Ct: time.Now(), Mt: utee.Tick(), Apps: apps, } cp.DB(DB).C(C).Insert(m) // func (p *Student) incTest(){ // if err := p.ds.DB(DB).C(C).UpdateId(p.Id, bson.M{"$inc":bson.M{"visitTimes":1}});err!=nil { // log.Println("@err:",err) // } // } }
func main() { c := diskv.New(diskv.Options{ BasePath: "./my-diskv-data-directory", Transform: func(s string) []string { return []string{} }, CacheSizeMax: 1024 * 1024, // 1MB }) b, _ := json.Marshal(Test{Name: "figo", Tp: "android", Count: 1024}) c.Write("test", b) for k := range c.Keys(nil) { log.Println("@k:", k) d, _ := c.Read(k) v := &Test{} json.Unmarshal(d, v) log.Println("@name:", v.Name, "@count:", v.Count, "@tp:", v.Tp) } d, _ := c.Read("test") v := &Test{} json.Unmarshal(d, v) log.Println("@name:", v.Name, "@count:", v.Count, "@tp:", v.Tp) st := utee.Tick() // 1000* for i := 0; i < 100*10000; i++ { b, _ := json.Marshal(Test{Name: "figo", Tp: "android", Count: 1024}) c.Write(fmt.Sprint("test", i), b) // c.WriteStream(fmt.Sprint("test",i),strings.NewReader( string(b)),false) } log.Println("100,0000 write cost ", (utee.Tick() - st), "m second") st = utee.Tick() for k := range c.Keys(nil) { b, e := c.Read(k) if e != nil { log.Println("@error:", e) } v := &Test{} json.Unmarshal(b, v) log.Println("@name:", v.Name, "@count:", v.Count, "@tp:", v.Tp) } log.Println("100,0000 read cost ", (utee.Tick() - st), "m second") }