ZStringを使ったPrintfモジュールを作りたい人生だった
ZStringに組み込まれているものを使ってF#のPrintfモジュールに手が咥えられないか試してみたものの、成果は芳しくなかったので残骸だけ置いておきます。
https://github.com/pocketberserker/FSharp.ZPrintf
一番の問題はUtf16ValueStringBuilder向けのbprintfがうまく動かなかったこと。
https://github.com/pocketberserker/FSharp.ZPrintf/blob/a847d48e26912be2cff5ce516c5f65a7244c9349/src/FSharp.ZPrintf/ZPrintf.fs#L1532 で k
を呼び出す前は値が書き込まれているのに、k
内でBuilderの中身を見ると空っぽになっていてどうして…。
眠くて何か見落としているだけかもしれないので気が向いたら精査するかも。
一応ベンチマーク:
BenchmarkDotNet=v0.12.0, OS=Windows 10.0.18362 Intel Core i7-8650U CPU 1.90GHz (Kaby Lake R), 1 CPU, 8 logical and 4 physical cores .NET Core SDK=3.1.201 [Host] : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT DEBUG DefaultJob : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT
Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|
StringPlus | 148.3 ns | 1.67 ns | 1.56 ns | 0.0706 | - | - | 296 B |
StringConcat | 167.3 ns | 2.29 ns | 2.14 ns | 0.0880 | - | - | 368 B |
ZStringConcat | 103.3 ns | 1.35 ns | 1.19 ns | 0.0134 | - | - | 56 B |
StringFormat | 172.9 ns | 2.96 ns | 2.77 ns | 0.0305 | - | - | 128 B |
ZStringFormat | 201.7 ns | 1.50 ns | 1.40 ns | 0.0134 | - | - | 56 B |
Printf | 792.6 ns | 8.73 ns | 7.29 ns | 0.1221 | - | - | 512 B |
ZPrintf | 826.8 ns | 6.61 ns | 5.52 ns | 0.1049 | - | - | 440 B |
PrintfList | 347,051.2 ns | 6,814.98 ns | 6,374.74 ns | 15.1367 | - | - | 63477 B |
ZPrintfList | 341,261.4 ns | 3,644.64 ns | 3,409.20 ns | 15.1367 | - | - | 63587 B |
結果的にZStringのソースコード読み漁ったりPrintfモジュールの復習になったので :yoshi: