-
Notifications
You must be signed in to change notification settings - Fork 1
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
Comparison with ResultTypes #1
Comments
Hadn't seen that. Looking at it, they are indeed eerily similar. Implementation is a bit different, I use
while
|
Here is a benchmark: julia> using ResultTypes, Expect, BenchmarkTools
julia> @noinline function rt_integer_division(x::Int, y::Int)::Result{Int, DivideError}
if y == 0
return DivideError()
else
return div(x, y)
end
end
julia> @noinline function expect_integer_division(x::Int, y::Int)::Expect{Int, DivideError}
if y == 0
return DivideError()
else
return div(x, y)
end
end
julia> @noinline function rt_func2(x, y)
r = rt_integer_division(x, y)
if ResultTypes.iserror(r)
return 0
else
return unwrap(r)
end
end
julia> @noinline function expect_func2(x, y)
r = safe_divide(x, y)
if !isassigned(r)
return 0
else
return r[]
end
end julia> @btime for i = 1:10 rt_func2(3, i % 2) end
79.357 ns (0 allocations: 0 bytes)
julia> @btime for i = 1:10 expect_func2(3, i % 2) end
80.165 ns (0 allocations: 0 bytes)
julia> @btime rt_func2(3, 0)
8.279 ns (0 allocations: 0 bytes)
0
julia> @btime expect_func2(3, 0)
8.576 ns (0 allocations: 0 bytes)
0 So performance seems pretty much identical. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First of all, neat package!
Rust's
Result
type is mentioned in the README, so it may be worthwhile to compare and contrast this approach in the README with Eric Davies' Julia implementation, ResultTypes.jl.The text was updated successfully, but these errors were encountered: