本文整理汇总了Golang中testing.B.N方法的典型用法代码示例。如果您正苦于以下问题:Golang B.N方法的具体用法?Golang B.N怎么用?Golang B.N使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.B
的用法示例。
在下文中一共展示了B.N方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkLinearSearch
func BenchmarkLinearSearch(b *testing.B) {
b.N = 10000
var haystack []int
b.StopTimer()
for i := 0; i < b.N; i++ {
haystack = append(haystack, i)
}
needles := rand.Perm(b.N)
b.StartTimer()
for n := range needles {
if v := LinearSearch(n, haystack); v == -1 {
b.Fatalf("%d not found", n)
}
}
}
示例2: BenchmarkJournalQueuePop
func BenchmarkJournalQueuePop(b *testing.B) {
b.N = 1000000
var err error
var p []byte
var fq Queue
if fq, err = NewJournalQueue(fpath); err != nil {
panic(err)
}
defer fq.Close()
defer os.RemoveAll(fpath)
b.ResetTimer()
b.StartTimer()
var total int64 = 0
for i := 0; i < b.N; i++ {
if p, err = fq.Pop(); err != nil {
b.FailNow()
return
}
total += int64(len(p))
c := int(binary.LittleEndian.Uint32(p))
l := int(binary.LittleEndian.Uint32(p[4:]))
if c != i || l != len(p) {
b.FailNow()
}
}
b.SetBytes(total / int64(b.N))
b.StopTimer()
}
示例3: BenchmarkPush
func BenchmarkPush(b *testing.B) {
stack := NewStack()
b.N = 102400
for i := 0; i < b.N; i++ {
stack.Push(i)
}
}
示例4: Benchmark_StringValue
func Benchmark_StringValue(b *testing.B) {
b.N = 1e6
str := strings.Repeat("a", 1000)
for i := 0; i < b.N; i++ {
__value = NewStringValue(str)
}
}
示例5: benchPutItemParallel
func benchPutItemParallel(p, c int, b *testing.B) {
svc := dynamodb.New(&aws.Config{
DisableSSL: aws.Bool(true),
})
av, err := dynamodbattribute.ConvertToMap(dbItem{Key: "MyKey", Data: "MyData"})
if err != nil {
b.Fatal("expect no ConvertToMap errors", err)
}
params := &dynamodb.PutItemInput{
Item: av,
TableName: aws.String(testTableName),
}
b.N = c
b.ResetTimer()
b.SetParallelism(p)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err = svc.PutItem(params)
if err != nil {
b.Error("expect no request errors", err)
}
}
})
}
示例6: Benchmark_LongValue
func Benchmark_LongValue(b *testing.B) {
b.N = 1e6
in := int64(10916927583729485)
for i := 0; i < b.N; i++ {
__value = NewLongValue(in)
}
}
示例7: BenchmarkGoRadixLookup
func BenchmarkGoRadixLookup(b *testing.B) {
var urls []string
tr := radix.New()
f, err := os.Open("testdata/url.txt")
if err != nil {
b.Fatal(err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
s := scanner.Text()
tr.Insert(s, len(urls))
urls = append(urls, s)
}
if err := scanner.Err(); err != nil {
b.Fatal(err)
}
b.N = len(urls)
b.ResetTimer()
for i := 0; i < b.N; i++ {
if v, _ := tr.Get(urls[i]); v != i {
b.Errorf("expect %d, got %d\n", i, v)
}
}
}
示例8: Benchmark_Pack_String____100
func Benchmark_Pack_String____100(b *testing.B) {
val := strings.Repeat("s", 100)
b.N = 1000
runtime.GC()
b.ResetTimer()
doPack(val, b)
}
示例9: Benchmark_BytesValue
func Benchmark_BytesValue(b *testing.B) {
b.N = 1e6
barr := bytes.Repeat([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 1000)
for i := 0; i < b.N; i++ {
__value = NewBytesValue(barr)
}
}
示例10: BenchmarkFilterConcurrent
func BenchmarkFilterConcurrent(b *testing.B) {
b.StopTimer()
b.N = 5000000
f := NewDataFilter("name", 3)
f.SetFilter("1000", "gt", 2000.0)
strmap := make([]string, 0)
for i := 0; i < 10000; i++ {
strmap = append(strmap, strconv.Itoa(i))
}
wg := sync.WaitGroup{}
workers := runtime.NumCPU()
each := b.N / workers
wg.Add(workers)
b.StartTimer()
for i := 0; i < workers; i++ {
go func() {
for i := 0; i < each; i++ {
f.Filter(strmap[i%10000], float64(i), i)
}
wg.Done()
}()
}
wg.Wait()
if len(f.GetAllFiltered()) != 3 {
b.Error("error, Filter")
}
}
示例11: BenchmarkAdd
func BenchmarkAdd(b *testing.B) {
b.StopTimer()
if err := exec.Command("rm", "-rf", "/tmp/rrd").Run(); err != nil {
b.Fatal(err)
}
if err := os.Mkdir("/tmp/rrd", 0755); err != nil {
b.Fatal(err)
}
for i := 0; i < 256; i++ {
if err := os.Mkdir(fmt.Sprintf("/tmp/rrd/%d", i), 0755); err != nil {
b.Fatal(err)
}
}
b.StartTimer()
b.N = b_size
n := b.N / work_size
for j := 0; j < work_size; j++ {
wg.Add(1)
go func(j int) {
defer wg.Done()
for i := 0; i < n; i++ {
filename := fmt.Sprintf("/tmp/rrd/%d/%d-%d.rrd", i%256, j, i)
add(b, filename)
}
}(j)
}
wg.Wait()
}
示例12: BenchmarkUpdate
func BenchmarkUpdate(b *testing.B) {
b.N = b_size
for i := 0; i < b.N; i++ {
update(b, fmt.Sprintf("/tmp/rrd/%d/%d.rrd", i&0xff, i))
}
}
示例13: Benchmark_IntegerValue
func Benchmark_IntegerValue(b *testing.B) {
b.N = 1e6
in := 1091
for i := 0; i < b.N; i++ {
__value = NewIntegerValue(in)
}
}
示例14: Benchmark_Pack_________Int32
func Benchmark_Pack_________Int32(b *testing.B) {
val := rand.Int31()
b.N = 1000
runtime.GC()
b.ResetTimer()
doPack(val, b)
}
示例15: bench
func bench(b *testing.B, grammar *ast.Grammar, parsers []testsuite.ResetParser, record bool) {
num := len(parsers)
if *bN != 0 {
b.N = *bN
}
var m *mem.Mem
var err error
if record {
m, err = mem.NewRecord(grammar)
} else {
m, err = mem.New(grammar)
}
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := parsers[i%num].Reset(); err != nil {
b.Fatal(err)
}
if _, err := m.Validate(parsers[i%num]); err != nil {
b.Fatal(err)
}
}
}