MCPcopy Create free account
hub / github.com/lib/pq / BenchmarkDecode

Function BenchmarkDecode

encode_test.go:399–452  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

397}
398
399func BenchmarkDecode(b *testing.B) {
400 b.Run("int64", func(b *testing.B) {
401 x := []byte("1234")
402 for i := 0; i < b.N; i++ {
403 decode(nil, x, oid.T_int8, formatText)
404 }
405 })
406 b.Run("float64", func(b *testing.B) {
407 x := []byte("3.14159")
408 for i := 0; i < b.N; i++ {
409 decode(nil, x, oid.T_float8, formatText)
410 }
411 })
412 b.Run("bool", func(b *testing.B) {
413 x := []byte{'t'}
414 for i := 0; i < b.N; i++ {
415 decode(nil, x, oid.T_bool, formatText)
416 }
417 })
418 b.Run("uuid_binary", func(b *testing.B) {
419 x := []byte{0x03, 0xa3, 0x52, 0x2f, 0x89, 0x28, 0x49, 0x87, 0x84, 0xd6, 0x93, 0x7b, 0x36, 0xec, 0x27, 0x6f}
420 for i := 0; i < b.N; i++ {
421 decodeUUIDBinary(x)
422 }
423 })
424 b.Run("timestamptz", func(b *testing.B) {
425 x := []byte("2013-09-17 22:15:32.360754-07")
426 for i := 0; i < b.N; i++ {
427 decode(&parameterStatus{}, x, oid.T_timestamptz, formatText)
428 }
429 })
430 b.Run("timestamptz_thread", func(b *testing.B) {
431 oldProcs := runtime.GOMAXPROCS(0)
432 defer runtime.GOMAXPROCS(oldProcs)
433 runtime.GOMAXPROCS(runtime.NumCPU())
434 pqtime.Reset()
435
436 x := []byte("2013-09-17 22:15:32.360754-07")
437 f := func(wg *sync.WaitGroup, loops int) {
438 defer wg.Done()
439 for i := 0; i < loops; i++ {
440 decode(&parameterStatus{}, x, oid.T_timestamptz, formatText)
441 }
442 }
443
444 wg := &sync.WaitGroup{}
445 b.ResetTimer()
446 for j := 0; j < 10; j++ {
447 wg.Add(1)
448 go f(wg, b.N/10)
449 }
450 wg.Wait()
451 })
452}
453
454func BenchmarkEncode(b *testing.B) {
455 b.Run("int64", func(b *testing.B) {

Callers

nothing calls this directly

Calls 3

ResetFunction · 0.92
decodeFunction · 0.85
decodeUUIDBinaryFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…