Created
November 23, 2020 08:20
-
-
Save medigor/69139294a1911ace69da4d3708119799 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
open System | |
open System.IO | |
open System.Text.Json | |
open System.Threading.Tasks | |
open FSharp.Control.Tasks.V2 | |
type MyRecord = { | |
Name: string | |
Age: int | |
Id: Guid | |
} | |
let writeJson () = | |
task { | |
use stream = File.OpenWrite "data.json" | |
let jwo = JsonWriterOptions(Indented = true) | |
use writer = new Utf8JsonWriter(stream, jwo) | |
writer.WriteStartArray() | |
for i = 1 to 10_000_000 do | |
let x = { | |
Name = Guid.NewGuid().ToString() | |
Age = 99 | |
Id = Guid.NewGuid()} | |
JsonSerializer.Serialize(writer, x) | |
if i % 1000 = 0 then | |
do! writer.FlushAsync() | |
writer.WriteEndArray() | |
do! writer.FlushAsync() | |
} | |
[<EntryPoint>] | |
let main argv = | |
writeJson () |> Task.WaitAll | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment