Created
July 23, 2012 07:32
-
-
Save ewalk153/3162425 to your computer and use it in GitHub Desktop.
Bufio example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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