当前位置: 首页>>代码示例>>Golang>>正文


Golang B.SetBytes方法代码示例

本文整理汇总了Golang中testing.B.SetBytes方法的典型用法代码示例。如果您正苦于以下问题:Golang B.SetBytes方法的具体用法?Golang B.SetBytes怎么用?Golang B.SetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.B的用法示例。


在下文中一共展示了B.SetBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: BenchmarkTarUntarWithLinks

func BenchmarkTarUntarWithLinks(b *testing.B) {
	origin, err := ioutil.TempDir("", "docker-test-untar-origin")
	if err != nil {
		b.Fatal(err)
	}
	tempDir, err := ioutil.TempDir("", "docker-test-untar-destination")
	if err != nil {
		b.Fatal(err)
	}
	target := filepath.Join(tempDir, "dest")
	n, err := prepareUntarSourceDirectory(100, origin, true)
	if err != nil {
		b.Fatal(err)
	}
	defer os.RemoveAll(origin)
	defer os.RemoveAll(tempDir)

	b.ResetTimer()
	b.SetBytes(int64(n))
	for n := 0; n < b.N; n++ {
		err := TarUntar(origin, target)
		if err != nil {
			b.Fatal(err)
		}
		os.RemoveAll(target)
	}
}
开发者ID:truedays,项目名称:docker,代码行数:27,代码来源:archive_test.go

示例2: BenchmarkParseSize

func BenchmarkParseSize(b *testing.B) {
	b.SetBytes(1)
	n := []byte("12345678")
	for i := 0; i < b.N; i++ {
		parseSize(n)
	}
}
开发者ID:picmonkey,项目名称:gnatsd,代码行数:7,代码来源:util_test.go

示例3: BenchmarkReplicaSnapshot

func BenchmarkReplicaSnapshot(b *testing.B) {
	defer tracing.Disable()()
	storeCfg := TestStoreConfig(nil)
	storeCfg.TestingKnobs.DisableSplitQueue = true
	stopper := stop.NewStopper()
	defer stopper.Stop()
	store := createTestStoreWithConfig(b, stopper, &storeCfg)
	// We want to manually control the size of the raft log.
	store.SetRaftLogQueueActive(false)

	rep, err := store.GetReplica(rangeID)
	if err != nil {
		b.Fatal(err)
	}

	snapSize := rep.GetMaxBytes()
	if err := fillTestRange(rep, snapSize); err != nil {
		b.Fatal(err)
	}
	b.SetBytes(snapSize)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		if _, err := rep.GetSnapshot(context.Background(), "bench"); err != nil {
			b.Fatal(err)
		}
		rep.CloseOutSnap()
	}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:29,代码来源:client_bench_test.go

示例4: BenchmarkUnmarshalText

func BenchmarkUnmarshalText(b *testing.B) {
	pb := new(MyMessage)
	for i := 0; i < b.N; i++ {
		UnmarshalText(benchInput, pb)
	}
	b.SetBytes(int64(len(benchInput)))
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:7,代码来源:text_parser_test.go

示例5: BenchmarkIndex1024

func BenchmarkIndex1024(b *testing.B) {
	i := ChecksumIndex{}
	i.weakChecksumLookup = make([]map[uint32]StrongChecksumList, 256)

	for x := 0; x < 1024; x++ {
		w := rand.Uint32()

		if i.weakChecksumLookup[w&255] == nil {
			i.weakChecksumLookup[w&255] = make(map[uint32]StrongChecksumList)
		}

		i.weakChecksumLookup[w&255][w] = append(
			i.weakChecksumLookup[w&255][w],
			chunks.ChunkChecksum{},
		)
	}

	b.SetBytes(1)
	b.StartTimer()
	for x := 0; x < b.N; x++ {
		i.FindWeakChecksum2(T)
	}
	b.StopTimer()

}
开发者ID:jbreiding,项目名称:go-sync,代码行数:25,代码来源:index_bench_test.go

示例6: BenchmarkNoHack

func BenchmarkNoHack(b *testing.B) {
	client, srv := net.Pipe()
	done := make(chan struct{})
	req := []byte("GET /foo\nHost: /var/run/docker.sock\nUser-Agent: Docker\n")
	read := make([]byte, 4096)
	b.SetBytes(int64(len(req) * 30))

	go func() {
		for {
			if _, err := srv.Write(req); err != nil {
				srv.Close()
				break
			}
		}
		close(done)
	}()

	for i := 0; i < b.N; i++ {
		for i := 0; i < 30; i++ {
			if _, err := client.Read(read); err != nil && err != io.EOF {
				b.Fatal(err)
			}
		}
	}
	client.Close()
	<-done
}
开发者ID:Tenk42,项目名称:docker,代码行数:27,代码来源:malformed_host_override_test.go

示例7: BenchmarkReadInts

func BenchmarkReadInts(b *testing.B) {
	var ls Struct
	bsr := &byteSliceReader{}
	var r io.Reader = bsr
	b.SetBytes(2 * (1 + 2 + 4 + 8))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		bsr.remain = big
		Read(r, BigEndian, &ls.Int8)
		Read(r, BigEndian, &ls.Int16)
		Read(r, BigEndian, &ls.Int32)
		Read(r, BigEndian, &ls.Int64)
		Read(r, BigEndian, &ls.Uint8)
		Read(r, BigEndian, &ls.Uint16)
		Read(r, BigEndian, &ls.Uint32)
		Read(r, BigEndian, &ls.Uint64)
	}
	b.StopTimer()
	want := s
	want.Float32 = 0
	want.Float64 = 0
	want.Complex64 = 0
	want.Complex128 = 0
	want.Array = [4]uint8{0, 0, 0, 0}
	want.Bool = false
	want.BoolArray = [4]bool{false, false, false, false}
	if b.N > 0 && !reflect.DeepEqual(ls, want) {
		b.Fatalf("struct doesn't match:\ngot  %v;\nwant %v", ls, want)
	}
}
开发者ID:achanda,项目名称:go,代码行数:30,代码来源:binary_test.go

示例8: BenchmarkBenchReadliner

func BenchmarkBenchReadliner(b *testing.B) {
	br := BenchReadliner{line: testLines[0], count: b.N}
	b.SetBytes(int64(len(br.line)))
	for i := 0; i < b.N; i++ {
		br.ReadLine()
	}
}
开发者ID:wuub,项目名称:feckless-octo-giggle,代码行数:7,代码来源:filter_test.go

示例9: BenchmarkUsersProd

func BenchmarkUsersProd(b *testing.B) {
	prodfile := "./prods/users.prod"
	text, err := ioutil.ReadFile(prodfile)
	if err != nil {
		b.Fatal(err)
	}
	seed := uint64(time.Now().UnixNano())

	s := parsec.NewScanner(text)
	root, _ := Y(s)
	scope := root.(common.Scope)
	nterms := scope["_nonterminals"].(common.NTForms)
	scope = BuildContext(scope, seed, "./bags", prodfile)

	b.ResetTimer()
	out := 0
	for i := 0; i < b.N; i++ {
		scope = scope.RebuildContext()
		if val, ok := EvalForms("root", scope, nterms["s"]).(string); !ok {
			b.Fatalf("not string `%v`\n", val)
		} else {
			out += len(val)
		}
	}
	b.SetBytes(int64(float64(out) / float64(b.N)))
}
开发者ID:abhi-bit,项目名称:monster,代码行数:26,代码来源:parser_test.go

示例10: BenchmarkSealLongMsg

// Benchmark sealing a 1MiB message.
func BenchmarkSealLongMsg(b *testing.B) {
	b.StopTimer()
	msg, err := ioutil.ReadFile("testdata/long.dat")
	if err != nil {
		fmt.Println("secretbox: failed to read short test message")
		fmt.Printf("%v\n", err)
		b.FailNow()
	}
	longMsg = msg
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		_, ok := Seal(msg, testKey)
		if !ok {
			fmt.Println("secretbox: failed to seal message")
			b.FailNow()
		}
		b.SetBytes(int64(len(msg)))
	}
	b.StopTimer()

	var ok bool
	longBox, ok = Seal(msg, testKey)
	if !ok {
		fmt.Println("secretbox: failed to seal message")
		b.FailNow()
	}
}
开发者ID:postfix,项目名称:cryptobox-ng,代码行数:29,代码来源:secretbox_test.go

示例11: BenchmarkUnma

func BenchmarkUnma(b *testing.B) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
	total := 0

	data := new(bytes.Buffer)
	enc := gob.NewEncoder(data)
	dec := gob.NewDecoder(data)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		b.StopTimer()

		p := NewPopulatedPreAccept(popr)

		enc.Encode(p)

		total += len(data.Bytes())

		msg := &PreAccept{}

		b.StartTimer()
		dec.Decode(&msg)

	}
	b.SetBytes(int64(total / b.N))
}
开发者ID:hongchaodeng,项目名称:serialization-bench,代码行数:26,代码来源:gob_test.go

示例12: BenchmarkFixedStreamWriter4K

func BenchmarkFixedStreamWriter4K(t *testing.B) {
	const totalinput = 10 << 20
	input := getBufferSize(totalinput)

	const size = 4 << 10
	b := input.Bytes()
	// Create some duplicates
	for i := 0; i < 500; i++ {
		// Read from 10 first blocks
		src := b[(i%10)*size : (i%10)*size+size]
		// Write into the following ones
		dst := b[(10+i)*size : (i+10)*size+size]
		copy(dst, src)
	}
	t.ResetTimer()
	t.SetBytes(totalinput)
	for i := 0; i < t.N; i++ {
		input = bytes.NewBuffer(b)
		w, _ := dedup.NewStreamWriter(ioutil.Discard, dedup.ModeFixed, size, 10*size)
		io.Copy(w, input)
		err := w.Close()
		if err != nil {
			t.Fatal(err)
		}
	}
}
开发者ID:klauspost,项目名称:dedup,代码行数:26,代码来源:writer_test.go

示例13: BenchmarkDynamicFragments64K

// Maximum block size:64k
func BenchmarkDynamicFragments64K(t *testing.B) {
	const totalinput = 10 << 20
	input := getBufferSize(totalinput)

	const size = 64 << 10
	b := input.Bytes()
	// Create some duplicates
	for i := 0; i < 50; i++ {
		// Read from 10 first blocks
		src := b[(i%10)*size : (i%10)*size+size]
		// Write into the following ones
		dst := b[(10+i)*size : (i+10)*size+size]
		copy(dst, src)
	}
	t.ResetTimer()
	t.SetBytes(totalinput)
	for i := 0; i < t.N; i++ {
		out := make(chan dedup.Fragment, 10)
		go func() {
			for _ = range out {
			}
		}()
		input = bytes.NewBuffer(b)
		w, _ := dedup.NewSplitter(out, dedup.ModeDynamic, size)
		io.Copy(w, input)
		err := w.Close()
		if err != nil {
			t.Fatal(err)
		}
	}
}
开发者ID:klauspost,项目名称:dedup,代码行数:32,代码来源:writer_test.go

示例14: BenchmarkEncode

func BenchmarkEncode(b *testing.B) {
	data := &Block{Bytes: make([]byte, 65536)}
	b.SetBytes(int64(len(data.Bytes)))
	for i := 0; i < b.N; i++ {
		Encode(ioutil.Discard, data)
	}
}
开发者ID:Greentor,项目名称:go,代码行数:7,代码来源:pem_test.go

示例15: BenchmarkNoDeferMutex

func BenchmarkNoDeferMutex(b *testing.B) {
	var mu sync.Mutex
	b.SetBytes(1)
	for i := 0; i < b.N; i++ {
		noDeferUnlock(&mu)
	}
}
开发者ID:picmonkey,项目名称:gnatsd,代码行数:7,代码来源:util_test.go


注:本文中的testing.B.SetBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。