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()
}
func benchReflect(b *testing.B, path string) {
	for i := 0; i < b.N; i++ {
		if Reflect(input, path) == nil {
			b.FailNow()
		}
	}
}
Example #3
0
func Benchmark6(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if Sort(6) {
			b.FailNow()
		}
	}
}
Example #4
0
func BenchmarkHbasePut(b *testing.B) {
	var (
		err error
		h   = NewHBaseClient()
		m   = &meta.Needle{}
		t   int64
	)
	ch := make(chan int64, 1000000)
	if err = Init("172.16.13.90:9090", 5*time.Second, 200, 200); err != nil {
		b.Errorf("Init failed")
		b.FailNow()
	}
	for j := 0; j < 1000000; j++ {
		k := int64(time.Now().UnixNano())
		ch <- k
	}
	b.ResetTimer()
	b.SetParallelism(8)
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			t = <-ch
			m.Key = t
			if err = h.Put(m); err != nil {
				continue
			}
		}
	})
}
Example #5
0
func testSeperateRouter(b *testing.B, server_r *Router, client_r *Router, n int, m int) {
	name := "scheduler"
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			var wg sync.WaitGroup
			for i := 0; i < m; i++ {
				req := pbt.NewResourceReq()
				req.Id = proto.Uint64(0)
				i := rand.Intn(n)
				if m == 1 {
					if _, err := client_r.CallWait(name+string(i), "rpc", req, 5); err != nil {
						b.Log(err)
						b.FailNow()
					}
				} else {
					wg.Add(1)
					client_r.Call(name+string(i), "rpc", req, ClientProcessReponseWaitGroup, &wg, 0)
				}
			}
			if m > 1 {
				wg.Wait()
			}
		}
	})

	client_r.Stop()
	server_r.Stop()
}
Example #6
0
func BenchmarkPipeShareRouter(b *testing.B) {
	r, err := NewRouter(nil, ServiceProcessPayload)
	if err != nil {
		b.FailNow()
	}

	hf := NewMsgHeaderFactory(pbt.NewMsgProtobufFactory())

	r.Run()
	<-time.Tick(1 * time.Millisecond)

	name := "scheduler"
	n := ConcurrentNum
	m := GoRoutineRequests
	for i := 0; i < n; i++ {
		c, s := net.Pipe()
		ep_c := r.newRouterEndPoint(name+string(i), c, hf)
		ep_s := r.newRouterEndPoint("client"+string(n), s, hf)
		r.AddEndPoint(ep_c)
		r.AddEndPoint(ep_s)
	}

	<-time.Tick(1 * time.Millisecond)
	testShareRouter(b, r, n, m)
}
Example #7
0
func runVmBench(test vmBench, b *testing.B) {
	db, _ := ethdb.NewMemDatabase()
	sender := state.NewStateObject(common.Address{}, db)

	if test.precompile && !test.forcejit {
		NewProgram(test.code)
	}
	env := NewEnv()

	EnableJit = !test.nojit
	ForceJit = test.forcejit

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		context := NewContext(sender, sender, big.NewInt(100), big.NewInt(10000), big.NewInt(0))
		context.Code = test.code
		context.CodeAddr = &common.Address{}
		_, err := New(env).Run(context, test.input)
		if err != nil {
			b.Error(err)
			b.FailNow()
		}
	}
}
Example #8
0
func Benchmark10k10k(b *testing.B) {
	f, err := os.Open("ips10k.txt")
	if err != nil {
		b.Log(err)
		b.FailNow()
	}
	loadSrc(f)
	b.StartTimer()
	fs, err := os.Open("query10k.txt")
	if err != nil {
		b.Log(err)
		b.FailNow()
	}
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		loadStats(fs)

		b.StopTimer()
		for _, v := range allRngs {
			v.count = 0
		}
		unkC = 0
		fs.Seek(0, 0)
		b.StartTimer()
	}
}
Example #9
0
func benchmarkStoreRead(b *testing.B, store data.Store) {
	var n = 1000
	benchmarkStoreInsert(b, store, n)
	b.ResetTimer()
	var users = store.Collection("users")
	for k := 0; k < b.N; k++ {
		var i = rand.Intn(n - 1)
		var name = fmt.Sprintf("user%d", i+1)
		var email = fmt.Sprintf("*****@*****.**", name)
		var usr User
		var err = users.Find(q.Or{
			q.M{"id": name},
			q.M{"name": name},
			q.M{"email": name},
		}).One(&usr)
		if err != nil {
			b.Errorf("find one failed with %v", err)
			b.FailNow()
		}
		err = users.Find(q.Or{
			q.M{"id": email},
			q.M{"name": email},
			q.M{"email": email},
		}).One(&usr)
		if err != nil {
			b.Errorf("find one failed with %v", err)
			b.FailNow()
		}
	}
}
Example #10
0
func BenchmarkLoadModel(b *testing.B) {
	client := New("127.0.0.1:8087")
	err := client.Connect()
	if err != nil {
		b.FailNow()
	}
	// Create a new "DocumentModel" and save it
	doc := DMInclude{Name: "some name", Sub: SubStruct{Value: "some value"}}
	err = client.New("testmodel.go", "BenchModelKey", &doc)
	if err != nil {
		b.Log(err)
		b.FailNow()
	}
	err = doc.Save()
	if err != nil {
		b.Log(err)
		b.Fail()
	}

	for i := 0; i < b.N; i++ {
		err = client.Load("testmodel.go", "BenchModelKey", &doc, R1)
		if err != nil {
			b.Log(err)
			b.Fail()
		}
	}
}
Example #11
0
func BenchmarkMain(tst *testing.B) {
	conn, err := grpc.Dial("localhost:4567", grpc.WithBlock())
	if err != nil {
		os.Exit(1)
	}
	defer conn.Close()

	client := pb.NewPingClient(conn)

	tst.ResetTimer()
	for n := 0; n < tst.N; n++ {
		ctx := context.Background()
		t := time.Now()
		req := pb.PingRequest{t.UnixNano()}
		_, err := client.Ping(ctx, &req)
		if err != nil {
			tst.FailNow()
		}

		/*
			t2 := time.Now()

			then := time.Unix(0, resp.TimeBack)

			reqdelay := then.Sub(t)
			log.Println("req ", reqdelay)

			repdelay := t2.Sub(then)
			log.Println("rep ", repdelay)
		*/
	}
}
Example #12
0
func startFakeBookingApp(b *testing.B) {
	Init("", "github.com/robfig/revel/samples/booking", "")

	// Disable logging.
	TRACE = log.New(ioutil.Discard, "", 0)
	INFO = TRACE
	WARN = TRACE
	ERROR = TRACE

	MainRouter = NewRouter("")
	routesFile, _ := ioutil.ReadFile(filepath.Join(BasePath, "conf", "routes"))
	MainRouter.parse(string(routesFile), false)
	MainTemplateLoader = NewTemplateLoader([]string{ViewsPath})
	MainTemplateLoader.Refresh()

	RegisterController((*Hotels)(nil),
		[]*MethodType{
			&MethodType{
				Name: "Show",
				Args: []*MethodArg{
					{"id", reflect.TypeOf((*int)(nil))},
				},
				RenderArgNames: map[int][]string{30: []string{"title", "hotel"}},
			},
		})

	RegisterController((*Static)(nil),
		[]*MethodType{
			&MethodType{
				Name: "Serve",
				Args: []*MethodArg{
					&MethodArg{Name: "prefix", Type: reflect.TypeOf((*string)(nil))},
					&MethodArg{Name: "filepath", Type: reflect.TypeOf((*string)(nil))},
				},
				RenderArgNames: map[int][]string{},
			},
		})

	plugins.OnAppStart()

	resp := httptest.NewRecorder()

	// First, test that the expected responses are actually generated
	handle(resp, showRequest)
	if !strings.Contains(resp.Body.String(), "300 Main St.") {
		b.Errorf("Failed to find hotel address in action response:\n%s", resp.Body)
		b.FailNow()
	}
	resp.Body.Reset()

	handle(resp, staticRequest)
	if resp.Body.Len() != 6712 {
		b.Errorf("Expected sessvars.js to have 6712 bytes, got %d:\n%s", resp.Body.Len(), resp.Body)
		b.FailNow()
	}

	resp.Body = nil
	b.ResetTimer()
}
Example #13
0
func BenchmarkShorten(b *testing.B) {
	for i := 0; i < b.N; i++ {
		shortid := Shorten()
		if len(shortid) != 6 {
			b.FailNow()
		}
	}
}
Example #14
0
// Benchmark the generation of P256 keys.
func BenchmarkGenerateKeyP256(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if _, err := GenerateKey(rand.Reader, elliptic.P256(), nil); err != nil {
			fmt.Println(err.Error())
			b.FailNow()
		}
	}
}
Example #15
0
func BenchmarkCheckRequestSignature(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if !CheckRequestSignature(req1, signerPub) {
			fmt.Print("crypto: signature verification failed")
			b.FailNow()
		}
	}
}
Example #16
0
func BenchmarkKeyGeneration(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if _, err := GenerateKey(); err != nil {
			fmt.Println(err.Error())
			b.FailNow()
		}
	}
}
Example #17
0
func benchmarkHTTPBatch(batchSize int, b *testing.B) {
	var wg sync.WaitGroup
	var components []interface{}

	f := NewRBForwarder(Config{
		Retries:   3,
		Backoff:   5,
		QueueSize: 10000,
	})

	batch := &batcher.Batcher{
		Config: batcher.Config{
			TimeoutMillis: 1000,
			Limit:         uint64(batchSize),
		},
	}
	components = append(components, batch)

	sender := &httpsender.HTTPSender{
		Config: httpsender.Config{
			URL: "http://localhost:8888",
		},
	}
	components = append(components, sender)

	f.PushComponents(components)
	sender.Client = NewTestClient(200, func(r *http.Request) {})

	f.Run()

	opts := map[string]interface{}{
		"http_endpoint": "test",
		"batch_group":   "test",
	}

	wg.Add(1)
	b.ResetTimer()
	go func() {
		for report := range f.GetReports() {
			r := report.(Report)
			if r.Code > 0 {
				b.FailNow()
			}
			if r.Opaque.(int) >= b.N-1 {
				break
			}
		}

		wg.Done()
	}()

	for i := 0; i < b.N; i++ {
		data := fmt.Sprintf("{\"message\": %d}", i)
		f.Produce([]byte(data), opts, i)
	}

	wg.Wait()
}
Example #18
0
func BenchmarkVolumeWrite(b *testing.B) {
	var (
		i     int
		v     *Volume
		err   error
		file  = "./test/testb2"
		ifile = "./test/testb2.idx"
		data  = make([]byte, 1*1024)
	)
	os.Remove(file)
	os.Remove(ifile)
	defer os.Remove(file)
	defer os.Remove(ifile)
	if _, err = rand.Read(data); err != nil {
		b.Errorf("rand.Read() error(%v)", err)
		b.FailNow()
	}
	if v, err = NewVolume(1, file, ifile); err != nil {
		b.Errorf("NewVolume() error(%v)", err)
		b.FailNow()
	}
	defer v.Close()
	b.SetParallelism(8)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		var (
			t    int64
			err1 error
			n    = &Needle{}
		)
		if err1 = n.Parse(t, t, data); err1 != nil {
			b.Errorf("n.Parse() error(%v)", err1)
			b.FailNow()
		}
		for pb.Next() {
			v.Lock()
			for i = 0; i < 9; i++ {
				t = mrand.Int63()
				n.Key = t
				n.Cookie = t
				if err1 = v.Write(n); err1 != nil {
					b.Errorf("Add() error(%v)", err1)
					v.Unlock()
					b.FailNow()
				}
				if err1 = v.Flush(); err1 != nil {
					b.Errorf("Flush() error(%v)", err1)
					v.Unlock()
					b.FailNow()
				}
			}
			v.Unlock()
			b.SetBytes(int64(n.TotalSize) * 9)
		}
	})
	os.Remove(file)
	os.Remove(ifile)
}
func benchmark(b *testing.B, fn func(string, string, uint, uint) error) {
	dir, _ := ioutil.TempDir("", "")
	for i := 0; i < b.N; i++ {
		if err := fn(filepath.Join(dir, fmt.Sprintf("totem_640_480_%d.jpg", i)), "totem.jpg", 640, 480); err != nil {
			b.Log(err)
			b.FailNow()
		}
	}
}
Example #20
0
// Benchmark the SharedKey function.
func BenchmarkSharedKey(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, ok := SharedKey(testGoodKey, testPeerPub)
		if !ok {
			fmt.Println("Computing shared key failed: benchmark aborted.")
			b.FailNow()
		}
	}
}
// Benchmark the generation of initialisation vectors.
func BenchmarkGenerateIV(b *testing.B) {
	for i := 0; i < b.N; i++ {
		iv, err := GenerateIV()
		if err != nil || len(iv) != BlockSize {
			b.FailNow()
		}
		Zeroise(&iv)
	}
}
// Benchmark the generation of long-term encryption keys.
func BenchmarkGenerateLTKey(b *testing.B) {
	for i := 0; i < b.N; i++ {
		key, err := GenerateLTKey()
		if err != nil || len(key) != KeySize {
			b.FailNow()
		}
		Zeroise(&key)
	}
}
Example #23
0
func BenchmarkSharedUnsignedSeal(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, ok := SealShared(testBoxFile, peerPublicList)
		if !ok {
			fmt.Println("Couldn't seal message: benchmark aborted.")
			b.FailNow()
		}
	}
}
Example #24
0
// Benchmark the Seal function, which secures the message.
func BenchmarkSeal(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, ok := Seal(testBoxFile, testGoodKey)
		if !ok {
			fmt.Println("Couldn't seal message: benchmark aborted.")
			b.FailNow()
		}
	}
}
Example #25
0
// Benchmark the generate of private keys.
func BenchmarkGenerateKey(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, err := GenerateKey(rand.Reader)
		if err != nil {
			fmt.Println(err.Error())
			b.FailNow()
		}
	}
}
Example #26
0
// Benchmark key generation.
func BenchmarkGenerateKey(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, err := GenerateKey(testPass, saltLen)
		if err != nil {
			fmt.Println("tkdf: failed to generate key")
			b.FailNow()
		}
	}
}
Example #27
0
func BenchmarkSignature(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, err := Sign(testkey, testmsg)
		if err != nil {
			fmt.Println(err.Error())
			b.FailNow()
		}
	}
}
Example #28
0
// Benchmark key restoration.
func BenchmarkKeyRestoration(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, err := RestoreKey(testPass, testKey.Salt)
		if err != nil {
			fmt.Println("tkdf: failed to restore key")
			b.FailNow()
		}
	}
}
Example #29
0
// Benchmark the generation of HMAC keys.
func BenchmarkGenerateHMACKey(b *testing.B) {
	for i := 0; i < b.N; i++ {
		key, err := GenerateHMACKey()
		if err != nil || len(key) != MacKeyLen {
			b.FailNow()
		}
		Zeroise(&key)
	}
}
Example #30
0
func Benchmark_ParseGherkinDocument(b *testing.B) { //benchmark function starts with "Benchmark" and takes a pointer to type testing.B
	for i := 0; i < b.N; i++ { // use b.N for looping
		r := strings.NewReader(benchmarkGherkinText)
		_, err := gherkin.ParseGherkinDocument(r)
		if err != nil {
			b.FailNow()
		}
	}
}