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


Golang testing.Benchmark函数代码示例

本文整理汇总了Golang中testing.Benchmark函数的典型用法代码示例。如果您正苦于以下问题:Golang Benchmark函数的具体用法?Golang Benchmark怎么用?Golang Benchmark使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: main

func main() {
	operation_name := "range"
	r1 := testing.Benchmark(Benchmark_slice)
	r2 := testing.Benchmark(Benchmark_map)
	fmt.Print(operation_name, "\n", "slice:", r1, r1.MemString(), "\n", "map:", r2, r2.MemString(), "\n")

}
开发者ID:Cergoo,项目名称:go_benchmark,代码行数:7,代码来源:main.go

示例2: TestBench

func TestBench(_ *testing.T) {

	seed := NewCryptoRandSeed()

	for _, name := range names {

		source := rand.New(NewHashSource(hashes[name], seed))

		r := testing.Benchmark(func(b *testing.B) {
			for i := 0; i < b.N; i++ {
				source.Int63()
			}
		})

		fmt.Println(name, r.String(), r.MemString())

	}

	source := rand.New(rand.NewSource(seed))

	r := testing.Benchmark(func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			source.Int63()
		}
	})

	fmt.Println("math/rand", r.String(), r.MemString())

}
开发者ID:jasonmoo,项目名称:rnd,代码行数:29,代码来源:rnd_test.go

示例3: main

func main() {
	operation_name := "Write"
	r1 = testing.Benchmark(benchmark_fastbuf)
	r2 = testing.Benchmark(benchmark_bytesbuf)
	fmt.Print(operation_name, "\n", "fastbuf:", r1, r1.MemString(), "\n", "bytes.Buffer:", r2, r2.MemString(), "\n")

}
开发者ID:catgatp,项目名称:gol,代码行数:7,代码来源:bench.go

示例4: main

func main() {
	fmt.Println(primitive.EndianBig())
	operation_name := "Write"
	r1 := testing.Benchmark(benchmark_buf1)
	r2 := testing.Benchmark(benchmark_buf2)
	fmt.Print(operation_name, "\n", "buf1:", r1, r1.MemString(), "\n", "buf2:", r2, r2.MemString(), "\n")

}
开发者ID:catgatp,项目名称:gol,代码行数:8,代码来源:bench.go

示例5: measureMul

// measureMul benchmarks math/big versus FFT for a given input size
// (in bits).
func measureMul(th int) (tBig, tFFT time.Duration) {
	bigLoad := func(b *testing.B) { benchmarkMulBig(b, th, th) }
	fftLoad := func(b *testing.B) { benchmarkMulFFT(b, th, th) }

	res1 := testing.Benchmark(bigLoad)
	res2 := testing.Benchmark(fftLoad)
	tBig = time.Duration(res1.NsPerOp())
	tFFT = time.Duration(res2.NsPerOp())
	return
}
开发者ID:remyoudompheng,项目名称:bigfft,代码行数:12,代码来源:calibrate_test.go

示例6: main

func main() {
	// The main test data
	data := []string{}

	for i := 0; i < TestSize; i++ {
		if i > CacheSize && rand.Float64() < RepeatChance {
			// Give a chance to recently used values, likely to happen in the
			// real world
			index := (rand.Int() % (CacheSize - 1)) + 1
			chosen := data[i-index]
			data = append(data, chosen)

		} else {
			// rnadomly change to 1 of 15 items
			randval := rand.Int() % UniqueElements
			data = append(data, strconv.Itoa(randval))
		}
	}

	// Set up the algorithms we're going to test
	algs := map[string]multicache.ReplacementAlgorithm{"Round Robin": &multicache.RoundRobin{},
		"LRU":           &multicache.LeastRecentlyUsed{},
		"Random":        &multicache.Random{},
		"Second Chance": &multicache.SecondChance{},
		"Timed Cache":   multicache.CreateTimeExpireAlgorithm(1000)}

	algnames := getSortedKeys(algs)

	for thread := 1; thread <= MaxThreads; thread++ {
		fmt.Printf("%d Threads\n", thread)
		runtime.GOMAXPROCS(thread)
		for _, algname := range algnames {
			alg := algs[algname]

			wrapped := wrapForParallelBenchmarking(data, alg, CacheSize, thread)

			result := testing.Benchmark(wrapped)
			showResults(algname, result)
		}

		// Test golang-lru
		wrapped := golangLruParallelBenchmarking(data, CacheSize)
		result := testing.Benchmark(wrapped)
		showResults("golang-lru", result)

		// Now test with a cache that holds all items
		wrapped = wrapForBenchmarking(data, &multicache.Random{}, UniqueElements)
		result = testing.Benchmark(wrapped)
		showResults("NONE", result)

		fmt.Println()
	}
}
开发者ID:evalphobia,项目名称:multicache,代码行数:53,代码来源:speedtest.go

示例7: main

func main() {
	var pr float32

	Init()
	t1 := testing.B{}
	t1.N = 10

	bf := testing.Benchmark(BenchmarkF)
	br := testing.Benchmark(BenchmarkR)
	pr = float32(br.NsPerOp()) / float32(bf.NsPerOp()) * 100
	fmt.Print("originu", bf, "\n", "type assert:", br, "\n", pr, "%", "\n")
}
开发者ID:Cergoo,项目名称:go_benchmark,代码行数:12,代码来源:reflection_benchmark.go

示例8: TestEfficiency

func TestEfficiency(t *testing.T) {
	var result testing.BenchmarkResult
	fmt.Println("Starting Efficiency Functions")

	fmt.Println("\nExample text file insert")
	for _, v := range trees {
		result = testing.Benchmark(benchText(v))
		fmt.Printf("%-30T %s\n", v, result)
	}

	fmt.Println("\nRandom Search")
	for _, v := range trees {
		result = testing.Benchmark(benchSearch(v))
		fmt.Printf("%-30T %s\n", v, result)
	}

	fmt.Println("\nRandom Search Dense")
	for _, v := range trees {
		result = testing.Benchmark(benchSearchDense(v))
		fmt.Printf("%-30T %s\n", v, result)
	}

	fmt.Println("\nLinear Insert")
	for _, v := range trees {
		result = testing.Benchmark(benchInsert(v))
		fmt.Printf("%-30T %s\n", v, result)
	}
	fmt.Println("\nRandom Insert")
	for _, v := range trees {
		result = testing.Benchmark(benchRandomInsert(v))
		fmt.Printf("%-30T %s\n", v, result)
	}

	fmt.Println("\nLinear Remove")
	for _, v := range trees {
		result = testing.Benchmark(benchRemove(v))
		fmt.Printf("%-30T %s\n", v, result)
	}
	fmt.Println("\nRandom Remove")
	for _, v := range trees {
		result = testing.Benchmark(benchRandomRemove(v))
		fmt.Printf("%-30T %s\n", v, result)
	}

	fmt.Println("\nInorder traverse")
	for _, v := range trees {
		result = testing.Benchmark(benchIterInorder(v))
		fmt.Printf("%-30T %s\n", v, result)
	}

	fmt.Println("\nInorder map")
	for _, v := range trees {
		result = testing.Benchmark(benchMap(v))
		fmt.Printf("%-30T %s\n", v, result)
	}

}
开发者ID:enjoylife,项目名称:balTree,代码行数:57,代码来源:common_test.go

示例9: TestBenchmark

func TestBenchmark(t *testing.T) {
	benchmarks := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 24, 31, 32, 63, 64, 100, 135, 256, 1 << 10}
	results := "Benchmark Results\n"
	for _, n := range benchmarks {
		slice := buildTestSlice(n, n)
		fast := testing.Benchmark(func(b *testing.B) { runBenchmark(FastSumUint8, slice, b) })
		slow := testing.Benchmark(func(b *testing.B) { runBenchmark(SumUint8, slice, b) })
		fastNsPerOp := float64(fast.T.Nanoseconds()) / float64(fast.N)
		slowNsPerOp := float64(slow.T.Nanoseconds()) / float64(slow.N)
		results += fmt.Sprintf("Length: %8d Fast:%12.2f ns/op Slow:%12.2f ns/op Improvement %6.2f%%\n", n, fastNsPerOp, slowNsPerOp, ((1/(fastNsPerOp/slowNsPerOp))-1)*100)
	}
	t.Log(results)
}
开发者ID:pietergvw,项目名称:superfastmatch,代码行数:13,代码来源:sum_test.go

示例10: main

func main() {
	runtime.GOMAXPROCS(2)

	bmResult := testing.Benchmark(Benchmark_sleeper)
	fmt.Println("sleep(3)", bmResult)
	bmResult = testing.Benchmark(Benchmark_go_sleeper)
	fmt.Println("5 go func", bmResult)
	bmResult = testing.Benchmark(Benchmark_fib)
	fmt.Println("fib(32)", bmResult)
	bmResult = testing.Benchmark(Benchmark_go_fib)
	fmt.Println("5 go fib(32)", bmResult)

}
开发者ID:rorcraft,项目名称:thread_sandbox,代码行数:13,代码来源:goroutine.go

示例11: main

func main() {
	fmt.Println(popcount.PopCount(4))
	fmt.Println(popcountLoop.PopCount(4))
	fmt.Println(popcountClearLsb.PopCount(4))
	fmt.Println(popcountShift64.PopCount(4))
	br := testing.Benchmark(BenchmarkPopcount)
	fmt.Println(br)
	br = testing.Benchmark(BenchmarkPopcountLoop)
	fmt.Println(br)
	br = testing.Benchmark(BenchmarkPopcountShift64)
	fmt.Println(br)
	br = testing.Benchmark(BenchmarkPopcountClearLsb)
	fmt.Println(br)
}
开发者ID:sdejean,项目名称:gopl-exercises,代码行数:14,代码来源:main.go

示例12: main

func main() {
	pattern := flag.String("p", "", "pattern to draw")
	sep := flag.String("s", "", "comma separated list of separators")
	fixture := flag.String("f", "", "fixture")
	verbose := flag.Bool("v", false, "verbose")
	flag.Parse()

	if *pattern == "" {
		flag.Usage()
		os.Exit(1)
	}

	var separators []rune
	for _, c := range strings.Split(*sep, ",") {
		if r, w := utf8.DecodeRuneInString(c); len(c) > w {
			fmt.Println("only single charactered separators are allowed")
			os.Exit(1)
		} else {
			separators = append(separators, r)
		}
	}

	g, err := glob.Compile(*pattern, separators...)
	if err != nil {
		fmt.Println("could not compile pattern:", err)
		os.Exit(1)
	}

	if !*verbose {
		fmt.Println(g.Match(*fixture))
		return
	}

	fmt.Printf("result: %t\n", g.Match(*fixture))

	cb := testing.Benchmark(func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			glob.Compile(*pattern, separators...)
		}
	})
	fmt.Println("compile:", benchString(cb))

	mb := testing.Benchmark(func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			g.Match(*fixture)
		}
	})
	fmt.Println("match:    ", benchString(mb))
}
开发者ID:letiemble,项目名称:syncthing,代码行数:49,代码来源:main.go

示例13: main

func main() {
	fmt.Printf("%5s %s\n", "loop", testing.Benchmark(benchmarkEmptyLoop).String())
	fmt.Printf("%5s %s\n", "+", testing.Benchmark(benchmarkAdd).String())
	fmt.Printf("%5s %s\n", "-", testing.Benchmark(benchmarkMinus).String())
	fmt.Printf("%5s %s\n", "*", testing.Benchmark(benchmarkProduct).String())
	fmt.Printf("%5s %s\n", "/", testing.Benchmark(benchmarkDivide).String())
	fmt.Printf("%5s %s\n", "if", testing.Benchmark(benchmarkIf).String())
	fmt.Printf("%5s %s\n", "print", testing.Benchmark(benchmarkPrint).String())
	fmt.Printf("%5s %s\n", "go", testing.Benchmark(benchmarkGo).String())
	fmt.Printf("%5s %s\n", "sched", testing.Benchmark(benchmarkGosched).String())
}
开发者ID:funkygao,项目名称:dlogmon,代码行数:11,代码来源:benchmark_base.go

示例14: main

func main() {
	var (
		std_json, gol_encodejson, gol_encodejsonFast testing.BenchmarkResult
		operation_name                               string
	)

	operation_name = "Encode"
	std_json = testing.Benchmark(Benchmark_std_json)
	gol_encodejson = testing.Benchmark(Benchmark_gol_encodejson)
	gol_encodejsonFast = testing.Benchmark(Benchmark_gol_encodejsonFast)
	fmt.Print(operation_name, "\n", "std_json:", std_json, std_json.MemString(),
		"\n", "gol_encodejson:", gol_encodejson, gol_encodejson.MemString(),
		"\n", "gol_encodejsonFast:", gol_encodejsonFast, gol_encodejsonFast.MemString(), "\n")

}
开发者ID:catgatp,项目名称:gol,代码行数:15,代码来源:main.go

示例15: runbench

func runbench(t *testing.T, path string, ignoreFuncBodies bool) {
	fset := token.NewFileSet()
	files, err := pkgFiles(fset, path)
	if err != nil {
		t.Fatal(err)
	}

	b := testing.Benchmark(func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			conf := Config{IgnoreFuncBodies: ignoreFuncBodies}
			conf.Check(path, fset, files, nil)
		}
	})

	// determine line count
	lines := 0
	fset.Iterate(func(f *token.File) bool {
		lines += f.LineCount()
		return true
	})

	d := time.Duration(b.NsPerOp())
	fmt.Printf(
		"%s: %s for %d lines (%d lines/s), ignoreFuncBodies = %v\n",
		filepath.Base(path), d, lines, int64(float64(lines)/d.Seconds()), ignoreFuncBodies,
	)
}
开发者ID:tintohill,项目名称:pythia,代码行数:27,代码来源:self_test.go


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