Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions wordcount/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ A simple timer has been used to track execution time.

Provide the name of the text file as a command line argument.

`go run main.go moby.txt`
`go run main.go sherlock.txt`

Example file to use:
https://www.gutenberg.org/cache/epub/2701/pg2701.txt
https://www.gutenberg.org/ebooks/100


# Execution time

For this branch:
`"shakespeare.txt": 741200 words, duration: 3422897ms`


# To view profile

`go tool pprof -http=:8080 cpuprofile.pprof`
Binary file added wordcount/cpuprofile.pprof
Binary file not shown.
Binary file added wordcount/cpuprofile01-moby.pprof
Binary file not shown.
Binary file added wordcount/cpuprofile02-shakespeare.pprof
Binary file not shown.
8 changes: 8 additions & 0 deletions wordcount/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"log"
"os"
"runtime/pprof"
"time"
"unicode"
)
Expand All @@ -21,6 +22,13 @@ func main() {
log.Fatalf("could not open file %q: %v", os.Args[1], err)
}

fc, err := os.Create("cpuprofile.pprof")
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(fc)
defer pprof.StopCPUProfile()

start := time.Now()
words := 0
inword := false
Expand Down
Loading