Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // reads in words from a local text file
- func scanLines(path string, results chan<- string) {
- file, err := os.Open(path)
- if err != nil {
- os.Exit(1)
- }
- defer file.Close()
- scanner := bufio.NewScanner(file)
- scanner.Split(bufio.ScanWords)
- for scanner.Scan() {
- results <- scanner.Text()
- }
- }
- // benchmark
- func BenchmarkScanLines(b *testing.B) {
- ch := make(chan string)
- go func() {
- for i := 0; i < b.N; i++ {
- scanLines("wordlist.txt", ch)
- }
- close(ch)
- }()
- for _ = range ch {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement