I have an issue on Linux Ubuntu with 1.4.2, which I am not sure how to sort:
func main() {
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
outputFile, outputError := os.OpenFile(dir+"/out1.csv",
os.O_WRONLY|os.O_CREATE, 0666)
if outputError != nil {
fmt.Printf("An error occurred with file creation
")
return
}
defer outputFile.Close()
writer := csv.NewWriter(outputFile)
results := getResults()
for _, result := range results {
writer.Write([]string{result.Item, result.Price, result.Shipping})
}
writer.Flush()
}
when results
is 1000+ records my PC freezes for seconds and when it's say 20k, it freezes for minutes.
How do I solve such an issue in a proper way?
I though to flush it every N records, and add time.Sleep
– but that looks awkward…