Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. // reads in words from a local text file
  2. func scanLines(path string, results chan<- string) {
  3. file, err := os.Open(path)
  4. if err != nil {
  5. os.Exit(1)
  6. }
  7. defer file.Close()
  8.  
  9. scanner := bufio.NewScanner(file)
  10. scanner.Split(bufio.ScanWords)
  11.  
  12. for scanner.Scan() {
  13. results <- scanner.Text()
  14. }
  15. }
  16.  
  17.  
  18. // benchmark
  19. func BenchmarkScanLines(b *testing.B) {
  20. ch := make(chan string)
  21. go func() {
  22. for i := 0; i < b.N; i++ {
  23. scanLines("wordlist.txt", ch)
  24. }
  25. close(ch)
  26. }()
  27. for _ = range ch {
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement