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

Side by Side Diff: src/pkg/exp/html/token_test.go

Issue 7027046: code review 7027046: testing: introduce (*B).EnableMallocReport() (Closed)
Patch Set: diff -r a55bd9f21507 https://code.google.com/p/go/ Created 11 years, 2 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:
View unified diff | Download patch
« no previous file with comments | « src/pkg/exp/html/parse_test.go ('k') | src/pkg/testing/benchmark.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 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 html 5 package html
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "io" 9 "io"
10 "io/ioutil" 10 "io/ioutil"
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 highLevel 627 highLevel
628 ) 628 )
629 629
630 func benchmarkTokenizer(b *testing.B, level int) { 630 func benchmarkTokenizer(b *testing.B, level int) {
631 buf, err := ioutil.ReadFile("testdata/go1.html") 631 buf, err := ioutil.ReadFile("testdata/go1.html")
632 if err != nil { 632 if err != nil {
633 b.Fatalf("could not read testdata/go1.html: %v", err) 633 b.Fatalf("could not read testdata/go1.html: %v", err)
634 } 634 }
635 b.SetBytes(int64(len(buf))) 635 b.SetBytes(int64(len(buf)))
636 runtime.GC() 636 runtime.GC()
637 » var ms runtime.MemStats 637 » b.ReportAllocs()
638 » runtime.ReadMemStats(&ms)
639 » mallocs := ms.Mallocs
640 b.ResetTimer() 638 b.ResetTimer()
641 for i := 0; i < b.N; i++ { 639 for i := 0; i < b.N; i++ {
642 z := NewTokenizer(bytes.NewBuffer(buf)) 640 z := NewTokenizer(bytes.NewBuffer(buf))
643 for { 641 for {
644 tt := z.Next() 642 tt := z.Next()
645 if tt == ErrorToken { 643 if tt == ErrorToken {
646 if err := z.Err(); err != nil && err != io.EOF { 644 if err := z.Err(); err != nil && err != io.EOF {
647 b.Fatalf("tokenizer error: %v", err) 645 b.Fatalf("tokenizer error: %v", err)
648 } 646 }
649 break 647 break
(...skipping 17 matching lines...) Expand all
667 case EndTagToken: 665 case EndTagToken:
668 z.TagName() 666 z.TagName()
669 } 667 }
670 case highLevel: 668 case highLevel:
671 // Calling z.Token converts []byte values to str ings whose validity 669 // Calling z.Token converts []byte values to str ings whose validity
672 // extend beyond the next call to z.Next. 670 // extend beyond the next call to z.Next.
673 z.Token() 671 z.Token()
674 } 672 }
675 } 673 }
676 } 674 }
677 b.StopTimer()
678 runtime.ReadMemStats(&ms)
679 mallocs = ms.Mallocs - mallocs
680 b.Logf("%d iterations, %d mallocs per iteration\n", b.N, int(mallocs)/b. N)
681 } 675 }
682 676
683 func BenchmarkRawLevelTokenizer(b *testing.B) { benchmarkTokenizer(b, rawLevel) } 677 func BenchmarkRawLevelTokenizer(b *testing.B) { benchmarkTokenizer(b, rawLevel) }
684 func BenchmarkLowLevelTokenizer(b *testing.B) { benchmarkTokenizer(b, lowLevel) } 678 func BenchmarkLowLevelTokenizer(b *testing.B) { benchmarkTokenizer(b, lowLevel) }
685 func BenchmarkHighLevelTokenizer(b *testing.B) { benchmarkTokenizer(b, highLevel ) } 679 func BenchmarkHighLevelTokenizer(b *testing.B) { benchmarkTokenizer(b, highLevel ) }
OLDNEW
« no previous file with comments | « src/pkg/exp/html/parse_test.go ('k') | src/pkg/testing/benchmark.go » ('j') | no next file with comments »

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