JuliaStrings / InlineStrings.jl

Fixed-width string types for Julia
Other
45 stars 13 forks source link

Allow concatenating small InlineStrings to return an InlineString #59

Closed nickrobinson251 closed 1 year ago

nickrobinson251 commented 1 year ago

Micro-benchmarks

using InlineStrings
using BenchmarkTools

s1 = InlineString1("a")
s3 = InlineString3("bb")
s7 = InlineString7("ccc")
s15 = InlineString15("dddd")

for s in (s1, s3, s7, s15)
    println(typeof(s))
    @btime $s * $s
    @btime $s * $s * $s
    @btime $s * $s * $s * $s
    @btime $s * $s * $s * $s * $s
end

Now (this PR)

String1
  2.125 ns (0 allocations: 0 bytes)
  2.125 ns (0 allocations: 0 bytes)
  2.084 ns (0 allocations: 0 bytes)
  7.125 ns (1 allocation: 24 bytes)
String3
  2.083 ns (0 allocations: 0 bytes)
  2.416 ns (0 allocations: 0 bytes)
  5.500 ns (0 allocations: 0 bytes)
  14.822 ns (1 allocation: 32 bytes)
String7
  2.416 ns (0 allocations: 0 bytes)
  4.500 ns (0 allocations: 0 bytes)
  19.163 ns (1 allocation: 32 bytes)
  22.234 ns (1 allocation: 32 bytes)
String15
  3.958 ns (0 allocations: 0 bytes)
  16.992 ns (1 allocation: 32 bytes)
  20.436 ns (1 allocation: 40 bytes)
  23.803 ns (1 allocation: 40 bytes)

Before (v1.3.2)

String1
  6.791 ns (1 allocation: 24 bytes)
  6.958 ns (1 allocation: 24 bytes)
  7.083 ns (1 allocation: 24 bytes)
  40.825 ns (6 allocations: 104 bytes)
String3
  9.844 ns (1 allocation: 24 bytes)
  11.678 ns (1 allocation: 24 bytes)
  13.263 ns (1 allocation: 32 bytes)
  48.963 ns (6 allocations: 112 bytes)
String7
  12.638 ns (1 allocation: 24 bytes)
  16.073 ns (1 allocation: 32 bytes)
  19.163 ns (1 allocation: 32 bytes)
  56.572 ns (6 allocations: 112 bytes)
String15
  13.597 ns (1 allocation: 32 bytes)
  16.951 ns (1 allocation: 32 bytes)
  20.416 ns (1 allocation: 40 bytes)
  59.070 ns (6 allocations: 200 bytes)

Run on v1.8.4:

julia> versioninfo()
Julia Version 1.8.4
Commit 00177ebc4fc (2022-12-23 21:32 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.5.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 1 on 8 virtual cores
nickrobinson251 commented 1 year ago

ooft, tests are failing because of the test for https://github.com/JuliaStrings/InlineStrings.jl/issues/2 😞

codecov-commenter commented 1 year ago

Codecov Report

Merging #59 (03445f4) into main (c8456ae) will increase coverage by 2.37%. The diff coverage is 95.42%.

@@            Coverage Diff             @@
##             main      #59      +/-   ##
==========================================
+ Coverage   90.65%   93.02%   +2.37%     
==========================================
  Files           1        1              
  Lines         460      674     +214     
==========================================
+ Hits          417      627     +210     
- Misses         43       47       +4     
Impacted Files Coverage Δ
src/InlineStrings.jl 93.02% <95.42%> (+2.37%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more