Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2657)

Delta Between Two Patch Sets: src/pkg/fmt/fmt_test.go

Issue 4850045: co: new package
Left Patch Set: Created 12 years, 7 months ago
Right Patch Set: diff -r d499fb951a9e https://go.googlecode.com/hg/ Created 12 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/co/test.go ('k') | src/pkg/fmt/print.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package fmt_test 5 package fmt_test
6 6
7 import ( 7 import (
8 . "fmt" 8 . "fmt"
9 "io" 9 "io"
10 "math" 10 "math"
11 "runtime" // for the malloc count test only 11 "runtime" // for the malloc count test only
12 "strings" 12 "strings"
13 "sync"
14 "sync/atomic"
13 "testing" 15 "testing"
14 ) 16 )
15 17
16 type ( 18 type (
17 renamedBool bool 19 renamedBool bool
18 renamedInt int 20 renamedInt int
19 renamedInt8 int8 21 renamedInt8 int8
20 renamedInt16 int16 22 renamedInt16 int16
21 renamedInt32 int32 23 renamedInt32 int32
22 renamedInt64 int64 24 renamedInt64 int64
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 Sprintf("%d %d", 5, 6) 468 Sprintf("%d %d", 5, 6)
467 } 469 }
468 } 470 }
469 471
470 func BenchmarkSprintfPrefixedInt(b *testing.B) { 472 func BenchmarkSprintfPrefixedInt(b *testing.B) {
471 for i := 0; i < b.N; i++ { 473 for i := 0; i < b.N; i++ {
472 Sprintf("This is some meaningless prefix text that needs to be s canned %d", 6) 474 Sprintf("This is some meaningless prefix text that needs to be s canned %d", 6)
473 } 475 }
474 } 476 }
475 477
478 func BenchmarkSprintfConcurrent(b *testing.B) {
479 const CallsPerSched = 1000
480 procs := runtime.GOMAXPROCS(-1)
481 N := int32(b.N / CallsPerSched)
482 var wg sync.WaitGroup
483 wg.Add(procs)
484 for p := 0; p < procs; p++ {
485 go func() {
486 for atomic.AddInt32(&N, -1) >= 0 {
487 for g := 0; g < CallsPerSched; g++ {
488 Sprintf("HTTP/%d.%d %d %s\r\n", 1, 1, 20 0, "OK")
489 }
490 runtime.Gosched()
491 }
492 wg.Done()
493 }()
494 }
495 wg.Wait()
496 }
497
476 func TestCountMallocs(t *testing.T) { 498 func TestCountMallocs(t *testing.T) {
477 if testing.Short() { 499 if testing.Short() {
478 return 500 return
479 } 501 }
480 runtime.UpdateMemStats() 502 runtime.UpdateMemStats()
481 mallocs := 0 - runtime.MemStats.Mallocs 503 mallocs := 0 - runtime.MemStats.Mallocs
482 for i := 0; i < 100; i++ { 504 for i := 0; i < 100; i++ {
483 Sprintf("") 505 Sprintf("")
484 } 506 }
485 runtime.UpdateMemStats() 507 runtime.UpdateMemStats()
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 759 }
738 760
739 func TestPanics(t *testing.T) { 761 func TestPanics(t *testing.T) {
740 for _, tt := range panictests { 762 for _, tt := range panictests {
741 s := Sprintf(tt.fmt, tt.in) 763 s := Sprintf(tt.fmt, tt.in)
742 if s != tt.out { 764 if s != tt.out {
743 t.Errorf("%q: got %q expected %q", tt.fmt, s, tt.out) 765 t.Errorf("%q: got %q expected %q", tt.fmt, s, tt.out)
744 } 766 }
745 } 767 }
746 } 768 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b