Skip to content

Surprising performance for ^(::Float64, ::Int) vs ^(::Complex128, ::Int) #23804

@saschatimme

Description

@saschatimme

With Julia 0.6 I get the following results

julia> y = rand();
julia> @benchmark ^($y, $3)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     22.666 ns (0.00% GC)
  median time:      25.019 ns (0.00% GC)
  mean time:        27.440 ns (0.00% GC)
  maximum time:     665.613 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     995
julia> x = rand(Complex128);
julia> @benchmark ^($x, $3)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     7.788 ns (0.00% GC)
  median time:      8.363 ns (0.00% GC)
  mean time:        9.346 ns (0.00% GC)
  maximum time:     90.948 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     999

So the complex case is faster than the float! #2741 I assume that the powi LLVM instruction isn't used by default, but it seems to be used for the complex case (I couldn't find the implementation :/) which is quite odd.
Update: Found the complex implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions