42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"git.dracodev.net/Projets/clip-sync/internal/dedup"
|
|
)
|
|
|
|
func BenchmarkHandleClipText(b *testing.B) {
|
|
cb := &mockClipboard{}
|
|
srv := newTestServer(cb, Options{MaxBodyBytes: 1 << 20})
|
|
|
|
body, _ := json.Marshal(dedup.Payload{
|
|
Text: "benchmark clipboard text", Ts: 1690000000000000000, Origin: "machine-b",
|
|
})
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
req := httptest.NewRequest(http.MethodPost, "/clip", bytes.NewReader(body))
|
|
w := httptest.NewRecorder()
|
|
srv.handleClip(w, req)
|
|
}
|
|
}
|
|
|
|
func BenchmarkHandleClipImage(b *testing.B) {
|
|
cb := &mockClipboard{}
|
|
srv := newTestServer(cb, Options{MaxBodyBytes: 1 << 20})
|
|
|
|
body := []byte(`{"mime":"image/png","data":"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==","ts":1,"origin":"machine-b"}`)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
req := httptest.NewRequest(http.MethodPost, "/clip", bytes.NewReader(body))
|
|
w := httptest.NewRecorder()
|
|
srv.handleClip(w, req)
|
|
}
|
|
}
|