Skip to content

Commit 085bd48

Browse files
fix: show large numbers
1 parent 1421ba3 commit 085bd48

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

Extensions/NumberExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace SqlcGenCsharp;
2+
3+
public static class NumberExtensions
4+
{
5+
public static string StringifyLargeNumbers(this int value)
6+
{
7+
if (value < 1000) return value.ToString();
8+
9+
var valueStr = value.ToString();
10+
if (valueStr.Length is >= 4 and <= 6) return $"{valueStr[0]}.{valueStr[1]}K";
11+
if (valueStr.Length is >= 7 and <= 9) return $"{valueStr[0]}.{valueStr[1]}M";
12+
if (valueStr.Length is >= 10 and <= 12) return $"{valueStr[0]}.{valueStr[1]}B";
13+
14+
throw new ArgumentException($"Number {value} is too large to stringify");
15+
}
16+
}

benchmark/BenchmarkRunner/BenchmarkRunner.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<ItemGroup>
1111
<ProjectReference Include="..\..\end2end\EndToEndCommon\EndToEndCommon.csproj" />
12+
<ProjectReference Include="..\..\Extensions\Extensions.csproj" />
1213
<ProjectReference Include="..\PostgresqlSqlcImpl\PostgresqlSqlcImpl.csproj" />
1314
<ProjectReference Include="..\PostgresqlEFCoreImpl\PostgresqlEFCoreImpl.csproj" />
1415
<ProjectReference Include="..\SqliteSqlcImpl\SqliteSqlcImpl.csproj" />

benchmark/BenchmarkRunner/Benchmarks/BaseReadBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
using BenchmarkDotNet.Attributes;
22
using BenchmarkRunner.Utils;
3+
using SqlcGenCsharp;
34

45
public readonly record struct ReadBenchmarkParams(
56
int Limit,
67
int Concurrency,
78
int QueriesToSubmit
89
)
910
{
10-
public override string ToString() => $"Limit={Limit}, Concurrency={Concurrency}, Queries={QueriesToSubmit:N0}";
11+
public override string ToString() => $"L={Limit.StringifyLargeNumbers()},C={Concurrency.StringifyLargeNumbers()},Q={QueriesToSubmit.StringifyLargeNumbers()}";
1112
}
1213

1314
public abstract class BaseReadBenchmark
1415
{
15-
1616
[IterationSetup]
1717
public static void IterationSetup() => Helpers.InvokeGarbageCollection();
1818
public abstract Task Sqlc_GetCustomerOrders();

benchmark/BenchmarkRunner/Benchmarks/BaseWriteBenchmark.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
using SqlcGenCsharp;
2+
13
public readonly record struct WriteBenchmarkArgs(
24
int TotalRecordsToLoad,
35
int BatchSize
46
)
57
{
6-
public override string ToString() => $"Records={TotalRecordsToLoad:N0}, BatchSize={BatchSize:N0}";
8+
public override string ToString() => $"R={TotalRecordsToLoad.StringifyLargeNumbers()},B={BatchSize.StringifyLargeNumbers()}";
79
}
810

911
public abstract class BaseWriteBenchmark

0 commit comments

Comments
 (0)