Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Most significant bit and bool-to-int conversions. #15

Merged
merged 3 commits into from
Jul 30, 2015

Conversation

redknightlois
Copy link
Contributor

It appears that the JIT is quite bad at optimizing Convert.Int32(bool)

// BenchmarkDotNet=v0.7.6.0
// OS=Microsoft Windows NT 6.2.9200.0
// Processor=Intel(R) Core(TM) i5-2500K CPU @ 3.30GHz, ProcessorCount=4
// CLR=MS.NET 4.0.30319.42000, Arch=64-bit [RyuJIT]
Common: Type=Jit_BoolToInt Mode=Throughput Platform=X64 .NET=Current

Method Jit AvrTime StdDev op/s
Framework LegacyJit 1.16 us 28.20 ns 858517.79
IfThenElse LegacyJit 1.08 us 44.58 ns 929458.93
UnsafeConvert LegacyJit 595.83 ns 5.79 ns 1678333.61
Framework RyuJit 1.31 us 18.64 ns 765539.56
IfThenElse RyuJit 1.31 us 16.05 ns 761023.73
UnsafeConvert RyuJit 896.80 ns 6.27 ns 1115078.04

@redknightlois
Copy link
Contributor Author

Updated the bool-to-int to avoid the use of arrays.

Results are even worse for RyuJIT

// BenchmarkDotNet=v0.7.6.0
// OS=Microsoft Windows NT 6.2.9200.0
// Processor=Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz, ProcessorCount=4
// CLR=MS.NET 4.0.30319.42000, Arch=64-bit [RyuJIT]
Common: Type=Jit_BoolToInt Mode=Throughput Platform=X64 .NET=Current

Method Jit AvrTime StdDev op/s
Framework LegacyJit 1.47 ns 0.0191 ns 678168087.72
IfThenElse LegacyJit 1.48 ns 0.0249 ns 676316149.82
UnsafeConvert LegacyJit 0.299 ns 0.00806 ns 3340169067.7
Framework RyuJit 2.97 ns 0.0216 ns 336993897.01
IfThenElse RyuJit 2.96 ns 0.0141 ns 338053580.07
UnsafeConvert RyuJit 8.59 ns 0.0329 ns 116442151.41

AndreyAkinshin added a commit that referenced this pull request Jul 30, 2015
Most significant bit and bool-to-int conversions.
@AndreyAkinshin AndreyAkinshin merged commit 52acca1 into dotnet:master Jul 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants