當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。