diff --git a/Sources/Towel/Slazy.cs b/Sources/Towel/Slazy.cs index 0852c2e0..4331439d 100644 --- a/Sources/Towel/Slazy.cs +++ b/Sources/Towel/Slazy.cs @@ -71,22 +71,22 @@ internal T GetValue() { if (_reference is not null) { - if (_reference._func is null) + if (reference._func is null) { - _value = _reference._value; + _value = reference._value; } else { try { - T value = _reference._func.Invoke(); - _reference._func = default; - _reference._value = value; + T value = reference._func.Invoke(); + reference._func = default; + reference._value = value; _value = value; } catch (Exception exception) { - _reference._func = () => throw exception; + reference._func = () => throw exception; throw; } } diff --git a/Tools/docfx_project/benchmarks/SlazyCachingBenchmarks.md b/Tools/docfx_project/benchmarks/SlazyCachingBenchmarks.md index ade7bbb7..d580cfa6 100644 --- a/Tools/docfx_project/benchmarks/SlazyCachingBenchmarks.md +++ b/Tools/docfx_project/benchmarks/SlazyCachingBenchmarks.md @@ -14,17 +14,17 @@ Intel Core i7-4790K CPU 4.00GHz (Haswell), 1 CPU, 8 logical and 4 physical cores ``` -| Method | N | Mean | Error | StdDev | Ratio | RatioSD | -|------- |----- |----------:|----------:|----------:|------:|--------:| -| **Lazy** | **1** | **31.01 ns** | **0.449 ns** | **0.398 ns** | **1.00** | **0.00** | -| SLazy | 1 | 26.70 ns | 0.252 ns | 0.236 ns | 0.86 | 0.01 | -| | | | | | | | -| **Lazy** | **10** | **36.83 ns** | **0.474 ns** | **0.420 ns** | **1.00** | **0.00** | -| SLazy | 10 | 29.16 ns | 0.404 ns | 0.378 ns | 0.79 | 0.01 | -| | | | | | | | -| **Lazy** | **100** | **91.55 ns** | **1.279 ns** | **1.134 ns** | **1.00** | **0.00** | -| SLazy | 100 | 81.45 ns | 1.136 ns | 1.007 ns | 0.89 | 0.02 | -| | | | | | | | -| **Lazy** | **1000** | **552.06 ns** | **11.075 ns** | **15.159 ns** | **1.00** | **0.00** | -| SLazy | 1000 | 518.34 ns | 3.411 ns | 3.024 ns | 0.93 | 0.03 | +| Method | N | Mean | Error | StdDev | Median | Ratio | RatioSD | +|------- |----- |----------:|----------:|----------:|----------:|------:|--------:| +| **Lazy** | **1** | **30.25 ns** | **0.545 ns** | **0.509 ns** | **30.17 ns** | **1.00** | **0.00** | +| SLazy | 1 | 23.57 ns | 0.297 ns | 0.277 ns | 23.47 ns | 0.78 | 0.02 | +| | | | | | | | | +| **Lazy** | **10** | **36.88 ns** | **0.761 ns** | **1.910 ns** | **36.69 ns** | **1.00** | **0.00** | +| SLazy | 10 | 27.13 ns | 0.158 ns | 0.140 ns | 27.09 ns | 0.72 | 0.04 | +| | | | | | | | | +| **Lazy** | **100** | **90.31 ns** | **1.656 ns** | **2.375 ns** | **89.69 ns** | **1.00** | **0.00** | +| SLazy | 100 | 81.43 ns | 1.630 ns | 2.586 ns | 80.60 ns | 0.91 | 0.02 | +| | | | | | | | | +| **Lazy** | **1000** | **531.13 ns** | **3.800 ns** | **3.173 ns** | **529.85 ns** | **1.00** | **0.00** | +| SLazy | 1000 | 530.96 ns | 10.452 ns | 17.749 ns | 521.25 ns | 1.03 | 0.03 | diff --git a/Tools/docfx_project/benchmarks/SlazyInitializationBenchmarks.md b/Tools/docfx_project/benchmarks/SlazyInitializationBenchmarks.md index 8caa583d..46a21564 100644 --- a/Tools/docfx_project/benchmarks/SlazyInitializationBenchmarks.md +++ b/Tools/docfx_project/benchmarks/SlazyInitializationBenchmarks.md @@ -10,25 +10,25 @@ BenchmarkDotNet=v0.13.0, OS=Windows 10.0.19042.1110 (20H2/October2020Update) Intel Core i7-4790K CPU 4.00GHz (Haswell), 1 CPU, 8 logical and 4 physical cores .NET SDK=6.0.100-preview.6.21355.2 [Host] : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT - Job-VGOPQH : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT + Job-RLZZYG : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT InvocationCount=1 UnrollFactor=1 ``` -| Method | N | Mean | Error | StdDev | Median | Ratio | RatioSD | -|------- |------ |-------------:|-------------:|-------------:|-------------:|------:|--------:| -| **Lazy** | **1** | **500.0 ns** | **0.00 ns** | **0.00 ns** | **500.0 ns** | **1.00** | **0.00** | -| SLazy | 1 | 341.8 ns | 23.05 ns | 67.23 ns | 300.0 ns | 0.63 | 0.12 | -| | | | | | | | | -| **Lazy** | **10** | **683.8 ns** | **15.48 ns** | **37.10 ns** | **700.0 ns** | **1.00** | **0.00** | -| SLazy | 10 | 433.3 ns | 13.44 ns | 37.48 ns | 450.0 ns | 0.63 | 0.07 | -| | | | | | | | | -| **Lazy** | **100** | **2,941.2 ns** | **60.21 ns** | **61.83 ns** | **2,900.0 ns** | **1.00** | **0.00** | -| SLazy | 100 | 2,426.1 ns | 48.96 ns | 61.92 ns | 2,400.0 ns | 0.82 | 0.03 | -| | | | | | | | | -| **Lazy** | **1000** | **25,069.2 ns** | **310.69 ns** | **259.44 ns** | **25,000.0 ns** | **1.00** | **0.00** | -| SLazy | 1000 | 20,933.3 ns | 106.93 ns | 83.48 ns | 20,950.0 ns | 0.83 | 0.01 | -| | | | | | | | | -| **Lazy** | **10000** | **234,102.1 ns** | **14,330.77 ns** | **41,117.66 ns** | **236,800.0 ns** | **1.00** | **0.00** | -| SLazy | 10000 | 201,431.0 ns | 6,087.77 ns | 16,665.16 ns | 203,300.0 ns | 0.87 | 0.14 | +| Method | N | Mean | Error | StdDev | Median | Ratio | RatioSD | +|------- |------ |-------------:|------------:|-------------:|-------------:|------:|--------:| +| **Lazy** | **1** | **429.2 ns** | **15.93 ns** | **40.84 ns** | **450.0 ns** | **1.00** | **0.00** | +| SLazy | 1 | 331.3 ns | 16.62 ns | 48.75 ns | 300.0 ns | 0.78 | 0.15 | +| | | | | | | | | +| **Lazy** | **10** | **700.0 ns** | **0.00 ns** | **0.00 ns** | **700.0 ns** | **1.00** | **0.00** | +| SLazy | 10 | 483.5 ns | 13.31 ns | 37.31 ns | 500.0 ns | 0.69 | 0.05 | +| | | | | | | | | +| **Lazy** | **100** | **2,976.9 ns** | **52.52 ns** | **43.85 ns** | **3,000.0 ns** | **1.00** | **0.00** | +| SLazy | 100 | 2,392.3 ns | 33.21 ns | 27.74 ns | 2,400.0 ns | 0.80 | 0.02 | +| | | | | | | | | +| **Lazy** | **1000** | **25,323.1 ns** | **170.44 ns** | **142.33 ns** | **25,300.0 ns** | **1.00** | **0.00** | +| SLazy | 1000 | 20,660.0 ns | 251.69 ns | 235.43 ns | 20,500.0 ns | 0.81 | 0.01 | +| | | | | | | | | +| **Lazy** | **10000** | **226,109.6 ns** | **9,479.85 ns** | **27,046.53 ns** | **237,300.0 ns** | **1.00** | **0.00** | +| SLazy | 10000 | 203,530.8 ns | 2,464.13 ns | 2,057.66 ns | 203,400.0 ns | 0.82 | 0.05 |