Created
August 9, 2023 19:25
-
-
Save valbaca/be31c25fb9bdfcf1495ae5c8524f6b87 to your computer and use it in GitHub Desktop.
This file contains 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 testers | |
import ( | |
"bufio" | |
"bytes" | |
"fmt" | |
"os" | |
"strconv" | |
) | |
func Valbaca_test(tot_rows int, buffer_size_mb int) { | |
work_dir, _ := os.UserHomeDir() | |
f_path := work_dir + "/test_dummy_data/perf_testing/bufio_test.csv" | |
file, _ := os.Create(f_path) | |
defer file.Close() | |
alloc_amt := buffer_size_mb * 1024 * 1024 | |
writer := bufio.NewWriterSize(file, alloc_amt) | |
defer writer.Flush() | |
var buffer bytes.Buffer | |
buffer_rows := (buffer_size_mb * 1024 * 1024) / 4 | |
row_cnt := 0 | |
newline := '\n' | |
for i := 1; i <= tot_rows; i++ { | |
buffer.WriteString(strconv.Itoa(i)) | |
buffer.WriteRune(newline) | |
row_cnt += 1 | |
//flush the buffer to disk if we hit the max size | |
if row_cnt >= buffer_rows || i == tot_rows { | |
_, err := buffer.WriteTo(writer) | |
if err != nil { | |
fmt.Println("Error writing data buffer to file: ", err) | |
return | |
} | |
//buffer.Reset() | |
row_cnt = 0 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment