Skip to content

Instantly share code, notes, and snippets.

@ewalk153
Created July 23, 2012 07:32
Show Gist options
  • Save ewalk153/3162425 to your computer and use it in GitHub Desktop.
Save ewalk153/3162425 to your computer and use it in GitHub Desktop.
Bufio example
package main
import (
"bufio"
"fmt"
"os"
"time"
)
/* simple go app showing the use of a buffered writer */
func main() {
LIMIT, fname := 1000000, "./foo.txt"
os.Remove(fname)
s := time.Now()
fo, err := os.Create(fname )
if err != nil {
panic(err)
}
defer fo.Close()
w := bufio.NewWriter(fo)
for i := 0; i < LIMIT; i++ {
if _, err := w.Write([]byte(fmt.Sprintf("%d,こんにちわ世界%03d\n", i, i))); err != nil {
panic(err)
}
}
if err = w.Flush(); err != nil {
panic(err)
}
fmt.Println("Completed in ", time.Since(s), LIMIT, "rows")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment