Ejemplo n.º 1
0
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")

}
Ejemplo n.º 2
0
func main() {

	bnative := testing.Benchmark(BenchmarkNative)
	batoi := testing.Benchmark(BenchmarkAtoi)

	fmt.Print("bnative:", bnative, "\n", "batoi:", batoi, "\n")
}
Ejemplo n.º 3
0
func main() {
	operation_name := "work"
	r1 := testing.Benchmark(Benchmark_chint)
	r2 := testing.Benchmark(Benchmark_chref)
	fmt.Print(operation_name, "\n", "ch int:", r1, r1.MemString(), "\n", "ch ref:", r2, r2.MemString(), "\n")

}
Ejemplo n.º 4
0
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())

}
Ejemplo n.º 5
0
Archivo: bench.go Proyecto: catgatp/gol
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")

}
Ejemplo n.º 6
0
func main() {
	bnative := testing.Benchmark(BenchmarkNative)
	breflect := testing.Benchmark(BenchmarkReflect)
	bslice := testing.Benchmark(BenchmarkSlice)

	fmt.Println("Get element benchmark:")
	fmt.Print("native_to_map:", bnative, "\n", "reflect_to_slice:", breflect, "\n", "native_to_slice:", bslice)
}
Ejemplo n.º 7
0
Archivo: bench.go Proyecto: catgatp/gol
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")

}
Ejemplo n.º 8
0
func main() {
	v1 = make([]string, 1000)
	v2 = make([]string, 1000)

	bnative := testing.Benchmark(BenchmarkNative)
	breflect := testing.Benchmark(BenchmarkReflect)

	fmt.Print("bnative:", bnative, "\n", "breflect:", breflect, "\n")
}
Ejemplo n.º 9
0
func main() {
	ch1 = make(chan []byte)
	go f2()
	operation_name := "work"
	r1 = testing.Benchmark(Benchmark_go)
	r2 = testing.Benchmark(Benchmark_ch)
	close(ch1)
	fmt.Print(operation_name, "\n", "go:", r1, r1.MemString(), "\n", "chan:", r2, r2.MemString(), "\n")

}
Ejemplo n.º 10
0
// 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
}
Ejemplo n.º 11
0
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()
	}
}
Ejemplo n.º 12
0
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")
}
Ejemplo n.º 13
0
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)
	}

}
Ejemplo n.º 14
0
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)
}
Ejemplo n.º 15
0
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)

}
Ejemplo n.º 16
0
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)
}
Ejemplo n.º 17
0
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))
}
Ejemplo n.º 18
0
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())
}
Ejemplo n.º 19
0
Archivo: main.go Proyecto: catgatp/gol
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")

}
Ejemplo n.º 20
0
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,
	)
}
Ejemplo n.º 21
0
func BenchmarkMain(*testing.B) {
	// Parallel benchmark for text/template.Template.Execute on a single object.
	testing.Benchmark(func(b *testing.B) {

		page := &Page{
			Title:          "Bob",
			FavoriteColors: []string{"blue", "green", "mauve"},
		}

		// RunParallel will create GOMAXPROCS goroutines
		// and distribute work among them.
		b.RunParallel(func(pb *testing.PB) {
			// Each goroutine has its own bytes.Buffer.
			var buf bytes.Buffer

			for pb.Next() {
				// The loop body is executed b.N times total across all goroutines.
				buf.Reset()

				_ = Home(&buf, page)

				fmt.Println(&buf)
			}
		})

	})
}
Ejemplo n.º 22
0
func main() {
	ktpl = kasia.MustParse(bench_kt)
	ktpl.EscapeFunc = nil
	gtpl = template.MustParse(bench_tpl, nil)
	for ii := 0; ii < len(bctx.Arr); ii++ {
		bctx.Arr[ii] = map[string]interface{}{
			"I": ii, "A": ii * 2,
			"B": `aąbcćdeęfghijklłmnńoóprsśtuvwxżż
                  AĄBCĆDEĘFGHIJKLŁMNŃOÓPRSŚTUVWXYŻŹ`,
		}
	}
	fmt.Println("Kasia:")
	fmt.Println(testing.Benchmark(kbench))
	fmt.Println("Go template:")
	fmt.Println(testing.Benchmark(tbench))
}
Ejemplo n.º 23
0
func main() {
	infile_epath := flag.String("infile", "", "wav file to read")
	flag.Parse()

	n := []uint32{1, 10, 100, 1000, 2000, 3000, 5000, 8000, 10000, 20000, 40000}

	var t int

	for _, numSamples := range n {
		result := testing.Benchmark(func(b *testing.B) {
			file, _ := os.Open(*infile_epath)
			reader := wav.NewReader(file)

			for {
				samples, err := reader.ReadSamples(numSamples)
				if err == io.EOF {
					break
				}
				for _, sample := range samples {
					t += reader.IntValue(sample, 0)
					t += reader.IntValue(sample, 1)
				}
			}
		})
		fmt.Printf("ReadSamples(%d): \t%s\n", numSamples, result.String())
	}
}
Ejemplo n.º 24
0
func Crack(password []byte, comp Compare) []byte {
	n := len(password)
	guess := make([]byte, n)
	for index := range password {
		times := make(Times, 0)
		for _, letter := range letters {
			guess[index] = letter
			result := T.Benchmark(func(b *T.B) {
				for i := 0; i < b.N; i++ {
					comp(password, guess)
				}
			})
			heap.Push(&times, TestRun{
				Time: result.NsPerOp(),
				Byte: letter,
			})
			log.Printf("took %s (%d ns/op) to try %q for index %d", result.T, result.NsPerOp(), letter, index)
		}
		tr := heap.Pop(&times).(TestRun)
		guess[index] = tr.Byte
		log.Printf("best guess is %q for index %d", tr.Byte, index)
		log.Printf("guess is now: %s", guess)
	}
	return guess
}
Ejemplo n.º 25
0
func main() {
	bs := []int{0, 1, 2, 5, 10, 50, 100, 200, 500, 1000, 5000}
	for _, s := range bs {
		buf = s
		fmt.Printf("%5d %s\n", buf, testing.Benchmark(benchmarkChan).String())
	}
}
Ejemplo n.º 26
0
// Bench sorting algorithms for SAMPLES powers of 2,
// saving the results to FILENAME.
func main() {
	// To add more algorithms to the graphical bencher,
	// add them to names and fns.
	//
	// No other part of this program need be modified.
	names := []string{"Insertion", "Merge"}
	fns := []func([]int){sort.Insertion, sort.Merge}

	ns := make([][]int64, len(fns))
	X := make([]int64, SAMPLES)

	N := 2
	for pow := 0; pow < len(X); pow++ {
		X[pow] = int64(N)
		N *= 2
	}

	for i, fn := range fns {
		log.Printf("Benching %s", names[i])
		ns[i] = make([]int64, len(X))
		for x, N := range X {
			result := testing.Benchmark(getBenchmarker(fn, int(N)))
			nsPerOp := result.NsPerOp()
			log.Printf("\t%d\t%d", N, nsPerOp)
			ns[i][x] = nsPerOp
		}
	}

	save(FILENAME, names, ns, X)
}
Ejemplo n.º 27
0
func runBenchmarkFor(fn func(*testing.B)) (seconds float64, err error) {
	bm := testing.Benchmark(fn)
	if (bm == testing.BenchmarkResult{}) {
		return 0, errors.New("failed")
	}
	return bm.T.Seconds() / float64(bm.N), nil
}
Ejemplo n.º 28
0
func BenchmarkBlockRewrites(n *core.IpfsNode, cfg *BenchCfg) error {
	buf := make([]byte, cfg.Blocksize)
	randbo.New().Read(buf)

	blk := blocks.NewBlock(buf)
	// write the block first, before starting the benchmark.
	// we're just looking at the time it takes to write a block thats already
	// been written
	k, err := n.Blocks.AddBlock(blk)
	if err != nil {
		return err
	}

	f := func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			_, err := n.Blocks.AddBlock(blk)
			if err != nil {
				b.Fatal(err)
			}
		}
	}

	br := testing.Benchmark(f)
	fmt.Printf("BlockRewrites:\t\t%s\n", br)

	// clean up
	err = n.Blocks.DeleteBlock(k)
	if err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 29
0
func benchAddSize(n *core.IpfsNode, cfg *BenchCfg, size int64) error {
	f := func(b *testing.B) {
		b.SetBytes(size)
		for i := 0; i < b.N; i++ {
			r := io.LimitReader(randbo.New(), size)
			spl := chunk.NewSizeSplitter(r, cfg.Blocksize)
			_, err := importer.BuildDagFromReader(n.DAG, spl, nil)
			if err != nil {
				fmt.Printf("ERRROR: ", err)
				b.Fatal(err)
			}
		}
	}

	br := testing.Benchmark(f)
	bs := humanize.IBytes(uint64(size))
	fmt.Printf("Add File (%s):\t%s\n", bs, br)

	err := cr.GarbageCollect(n, context.Background())
	if err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 30
0
func BenchmarkRandomBlockWrites(n *core.IpfsNode, cfg *BenchCfg) error {
	buf := make([]byte, cfg.Blocksize)
	read := randbo.New()

	var keys []key.Key
	f := func(b *testing.B) {
		b.SetBytes(cfg.Blocksize)
		for i := 0; i < b.N; i++ {
			read.Read(buf)
			blk := blocks.NewBlock(buf)
			k, err := n.Blocks.AddBlock(blk)
			if err != nil {
				b.Fatal(err)
			}

			keys = append(keys, k)
		}
	}

	br := testing.Benchmark(f)
	fmt.Printf("RandomBlockWrites:\t%s\n", br)

	// clean up
	for _, k := range keys {
		err := n.Blocks.DeleteBlock(k)
		if err != nil {
			return err
		}
	}

	return nil
}