# Performance of cld vs ceil

**URL:** <https://discourse.julialang.org/t/performance-of-cld-vs-ceil/68309>\
**Category:** Performance\
**Tags:** question\
**Created:** [September 17, 2021, 5:56am UTC](https://discourse.julialang.org/t/performance-of-cld-vs-ceil/68309 "2021-09-17T05:56:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 17, 2021, 5:56am UTC](https://discourse.julialang.org/t/performance-of-cld-vs-ceil/68309/1 "2021-09-17T05:56:50Z")

</div>

For floating-point arguments,

```julia
julia> x = 5.5; y = 2.2;

julia> @btime cld($(Ref(x))[], $(Ref(y))[])
  23.836 ns (0 allocations: 0 bytes)
3.0

julia> @btime ceil(($(Ref(x))[] / $(Ref(y))[]))
  2.682 ns (0 allocations: 0 bytes)
3.0

```

Why is `cld` so much slower than `ceil`?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 17, 2021, 6:04am UTC](https://discourse.julialang.org/t/performance-of-cld-vs-ceil/68309/2 "2021-09-17T06:04:50Z")

</div>

It looks like we are calling the wrong method for it accidentally. We are currently calling `cld(x::T, y::T) where T<:AbstractFloat in Base at float.jl:422`, but we should be calling `cld(a::T, b::T) where T<:Union{AbstractFloat, Integer} in Base at div.jl:269`. I’m not sure what caused this.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 17, 2021, 7:07am UTC](https://discourse.julialang.org/t/performance-of-cld-vs-ceil/68309/3 "2021-09-17T07:07:11Z")

</div>

> [@Oscar\_Smith](#):
>
> I’m not sure what caused this.

Non-union argument is “more specific” than union argument? I think this should’ve errored ambigously.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 17, 2021, 1:28pm UTC](https://discourse.julialang.org/t/performance-of-cld-vs-ceil/68309/4 "2021-09-17T13:28:36Z")

</div>

this isn’t an ambiguity error because the union is strictly less specific. what I meant is I’m not sure went we have the worse method defined at all.
