JuliaLang/julia

`allunique(::String)` performance anomaly

Open

#50,360 opened on Jun 29, 2023

View on GitHub
 (17 comments) (0 reactions) (0 assignees)Julia (5,773 forks)batch import
good first issueperformancestrings

Repository metrics

Stars
 (48,709 stars)
PR merge metrics
 (Avg merge 20d 6h) (157 merged PRs in 30d)

Description

It seems that allunique is not short-circuiting efficiently for strings

julia> VERSION
v"1.10.0-DEV.1604"

julia> using Random

julia> using BenchmarkTools

julia> s=randstring(100000);

julia> @btime allunique(s)
  140.850 μs (7 allocations: 848 bytes)
false

julia> @btime allunique(s[1:100]) && allunique(s)
  575.746 ns (8 allocations: 968 bytes)
false

140 μs >> 575 ns

Contributor guide