-
Notifications
You must be signed in to change notification settings - Fork 0
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
when using a constant value when case when checking values... 0.0B/op appears. #1
Comments
How can |
Actually, I think I understand why. 0.0B/op is short hand for: Bytes Per Operation, correct? If so, the amount of bytes for a constant conditional.. doesn't take that much. Thus, it probably rounds down to 0.0. Do I got that right? With that said, it would make sense to use .shuffle. However, I don't know if |
Could you post the benchmark code? |
hello @exilor Here is a reduced example:
Output:
|
Check this enum CMD
XFER
end
TEST_STR = "FDGRRGERG1".reverse.reverse
Benchmark.ips do |x|
x.report("case_when_enum") { case_when_enum }
x.report("case_when_string") { case_when_string }
end
def case_when_enum
cmd = CMD.from_value 0
cmd == CMD::XFER
end
def case_when_string
cmd = TEST_STR
cmd == "FDGRRGERG1"
end And my results:
As to what are B/op... I don't know. |
@exilor Maybe.. .shuffle is correct then so it checks against different strings on each iteration? (randomly)? I just didn't want to use shuffle cause maybe it could distort the actual performance of checking an enum value vs a string (cause it has to shuffle the elements, which is a performance factor intrinsically) edit: One second, thanks for your code, going to try something now. |
New code:
Output:
Now checking Enum values is slower than a string. I don't know how to do this :/ |
Now that benchmark is comparing bytesizes between strings, which is also very cheap like what happened before. |
@exilor I see. Interesting, thanks for the info! |
This seems weird, when constant values are enabled for case when checking (example):
cmd = CMD.from_value 5
instead of
cmd = CMD.from_value CMD_INDEX_VALUES.shuffle[0]
the Benchmark will report:
The text was updated successfully, but these errors were encountered: