コード例 #1
0
func BenchmarkDelete(b *testing.B) {
	var objmap interface{}
	client := Client{Organization: "yourorgname", Application: "sandbox", Uri: "https://api.usergrid.com"}
	params := map[string]string{"limit": strconv.Itoa(500)}
	err := client.Get("benchmark", params, JSONResponseHandler(&objmap))
	if err != nil {
		b.Logf("Test failed: %s\n", err)
		b.Fail()
	}
	omap := objmap.(map[string]interface{})
	if omap["entities"] == nil || len(omap["entities"].([]interface{})) == 0 {
		b.Logf("Test failed: no entities to delete\n")
		b.Fail()
	}
	entities := omap["entities"].([]interface{})
	var entity map[string]interface{}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		if len(entities) == 0 {
			b.Logf("Test failed: we ran out of entities\n")
			b.Fail()
			continue
		}
		entity, entities = entities[len(entities)-1].(map[string]interface{}), entities[:len(entities)-1]
		err := client.Delete("benchmark/"+entity["uuid"].(string), nil, NOOPResponseHandler(&objmap))
		if err != nil {
			b.Logf("BenchmarkDelete failed: %s\n", err)
			b.Fail()
		}
	}
	if b.Failed() {
		str, _ := json.MarshalIndent(objmap, "", "  ")
		b.Logf("RESPONSE: %s", str)
	}
}
コード例 #2
0
ファイル: bench_test.go プロジェクト: zhaohaidao/libchan
func SpawnLocalPipeBench(b *testing.B, sender BenchMessageSender, receiver BenchMessageReceiver) {
	endClient := make(chan bool)
	endServer := make(chan bool)

	receiver1, sender1 := libchan.Pipe()

	go BenchClient(b, endClient, sender1, sender, b.N)
	go BenchServer(b, endServer, receiver1, receiver, b.N)

	timeout := time.After(time.Duration(b.N+1) * 50 * time.Millisecond)

	for endClient != nil || endServer != nil {
		select {
		case <-endClient:
			if b.Failed() {
				b.Fatal("Client failed")
			}
			endClient = nil
		case <-endServer:
			if b.Failed() {
				b.Fatal("Server failed")
			}
			endServer = nil
		case <-timeout:
			if DumpStackOnTimeout {
				pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
			}
			b.Fatal("Timeout")
		}
	}
}
コード例 #3
0
ファイル: messages_test.go プロジェクト: yonglehou/gostorm
func BenchmarkMarshalJSON(b *testing.B) {
	msg := getMessage()
	msg.ShellMsgJson.Contents = getTestTuple()
	for i := 0; i < b.N; i++ {
		_, err := json.Marshal(msg)
		if err != nil {
			b.Log("Error: ", err)
			b.Failed()
		}
	}
}
コード例 #4
0
ファイル: bench_test.go プロジェクト: zhaohaidao/libchan
func SpawnSpdyProxyBench(b *testing.B, sender BenchMessageSender, receiver BenchMessageReceiver) {
	endClient := make(chan bool)
	endServer := make(chan bool)
	endProxy1 := make(chan bool)
	endProxy2 := make(chan bool)

	receiver1, sender1, err := testPipe()
	if err != nil {
		b.Fatalf("Error creating pipe: %s", err)
	}
	receiver2, sender2, err := testPipe()
	if err != nil {
		b.Fatalf("Error creating pipe: %s", err)
	}
	receiver3, sender3, err := testPipe()
	if err != nil {
		b.Fatalf("Error creating pipe: %s", err)
	}

	go BenchProxy(b, endProxy1, sender2, receiver1, b.N)
	go BenchProxy(b, endProxy2, sender3, receiver2, b.N)
	go BenchClient(b, endClient, sender1, sender, b.N)
	go BenchServer(b, endServer, receiver3, receiver, b.N)

	timeout := time.After(time.Duration(b.N+1) * 200 * time.Millisecond)

	for endClient != nil || endServer != nil || endProxy1 != nil || endProxy2 != nil {
		select {
		case <-endProxy1:
			if b.Failed() {
				b.Fatal("Proxy failed")
			}
			endProxy1 = nil
		case <-endProxy2:
			if b.Failed() {
				b.Fatal("Proxy failed")
			}
			endProxy2 = nil
		case <-endClient:
			if b.Failed() {
				b.Fatal("Client failed")
			}
			endClient = nil
		case <-endServer:
			if b.Failed() {
				b.Fatal("Server failed")
			}
			endServer = nil
		case <-timeout:
			if DumpStackOnTimeout {
				pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
			}
			b.Fatal("Timeout")
		}
	}
}
コード例 #5
0
ファイル: parser_test.go プロジェクト: c4pt0r/tidb
func BenchmarkParse(b *testing.B) {
	var table = []string{
		"insert into t values (1), (2), (3)",
		"insert into t values (4), (5), (6), (7)",
		"select c from t where c > 2",
	}
	parser := New()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		for _, v := range table {
			_, err := parser.Parse(v, "", "")
			if err != nil {
				b.Failed()
			}
		}
	}
	b.ReportAllocs()
}
コード例 #6
0
func BenchmarkPost(b *testing.B) {
	var objmap interface{}
	client := Client{Organization: "yourorgname", Application: "sandbox", Uri: "https://api.usergrid.com"}
	data := map[string]string{"index": "0", "description": "golang benchmark"}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		data["index"] = strconv.Itoa(i)
		err := client.Post("benchmark", nil, data, JSONResponseHandler(&objmap))
		if err != nil {
			b.Logf("BenchmarkPost failed: %s\n", err)
			b.Fail()
		}
		if b.Failed() {
			str, _ := json.MarshalIndent(objmap, "", "  ")
			b.Logf("RESPONSE: %s", str)
		}
	}
}
コード例 #7
0
ファイル: go1_6.go プロジェクト: rawlingsj/gofabric8
// Bench runs the given benchmark function. This pre-1.7 implementation renders
// the measurement useless, but allows the code to be compiled at least.
func Bench(b *testing.B, name string, fn func(b *testing.B)) bool {
	b.Logf("Running %s...", name)
	fn(b)
	return b.Failed()
}