func benchmarkSize(b *testing.B, size int) { fileName := utils.GetRoot("/test/bitmap/benchmark") os.RemoveAll(fileName) f, err := NewFileEx(fileName, 22) if err != nil { b.Fatal(err) } defer func() { f.Delete() }() b.ResetTimer() data := []byte(strings.Repeat(utils.RandString(1), size)) w := utils.Writer{f, 0} for i := 0; i < b.N; i++ { w.Write(data) b.SetBytes(int64(len(data))) } }
// Testing read and write multiple files one time func TestMultiReadWrite(t *testing.T) { var err error defer utils.TDefer(t, &err) ins, err := newIns() if err != nil { return } defer ins.Close() label := []string{ "test1", "test2", "test3", "test4", "test5", "test6", "test7", } data := [][]byte{ genBlock(2), genBlock(20), genBlock(9), genBlock(15), genBlock(ins.cfg.blkSize + 2), genBlock(2*ins.cfg.blkSize + 21), genBlock(ins.cfg.blkSize + 1), } testTime := 2 for jj := 0; jj < testTime; jj++ { // write two file once ws := make([]*utils.Writer, len(label)) for i, l := range label { var w *utils.Writer w, err = ins.OpenWriter(l) if err != nil { return } ws[i] = w defer w.Close() } for i := range label { if err = safeWrite(ws[i], data[i]); err != nil { return } } } for jj := 0; jj < testTime; jj++ { // read two file once rs := make([]*utils.Reader, len(label)) for i, l := range label { var r *utils.Reader r, err = ins.OpenReader(l) if err != nil { return } defer r.Close() rs[i] = r } for i := range label { if err = safeReadExpect(rs[i], data[i]); err != nil { return } } } err = nil return }