Created
January 17, 2021 09:24
IDIV vs SHR.cs
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
public class Bench6 | |
{ | |
int div = 10; | |
int by = 4; | |
[Benchmark(Baseline = true)] | |
public int Div() | |
{ | |
var a = div; | |
var b = by; | |
int all = 0; | |
all += a / b; | |
all += a / b; | |
all += a / b; | |
all += a / b; | |
all += a / b; | |
all += a / b; | |
all += a / b; | |
all += a / b; | |
return all; | |
} | |
[Benchmark] | |
public int DivReduced() | |
{ | |
var a = div; | |
int all = 0; | |
all += a / 4; | |
all += a / 4; | |
all += a / 4; | |
all += a / 4; | |
all += a / 4; | |
all += a / 4; | |
all += a / 4; | |
all += a / 4; | |
return all; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment