ruby/benchmark/array_join.yml
Yaroslav Markin 35b7652058 Speed up Array#join with a memcpy fast path
When every element is a String sharing one ASCII-compatible fast-path
encoding (UTF-8/US-ASCII/ASCII-8BIT) and the separator is compatible, build
the result with a single memcpy pass instead of appending element by element
through rb_str_buf_append. Other cases fall back to the existing path.
2026-06-11 20:59:01 +02:00

35 lines
1.3 KiB
YAML

prelude: |
# All elements are 7-bit ASCII Strings (the dominant real-world join case).
# Distinct objects so large-N cases exercise realistic heap/cache behavior.
a100_1 = Array.new(100) { "a" * 1 }
a100_8 = Array.new(100) { "a" * 8 }
a100_40 = Array.new(100) { "a" * 40 }
a1k_1 = Array.new(1000) { "a" * 1 }
a1k_8 = Array.new(1000) { "a" * 8 }
a1k_40 = Array.new(1000) { "a" * 40 }
a100k_1 = Array.new(100000) { "a" * 1 }
a100k_8 = Array.new(100000) { "a" * 8 }
a100k_40 = Array.new(100000) { "a" * 40 }
benchmark:
# separator " " (space)
join_sp_n100_e1: a100_1.join(" ")
join_sp_n100_e8: a100_8.join(" ")
join_sp_n100_e40: a100_40.join(" ")
join_sp_n1k_e1: a1k_1.join(" ")
join_sp_n1k_e8: a1k_8.join(" ")
join_sp_n1k_e40: a1k_40.join(" ")
join_sp_n100k_e1: a100k_1.join(" ")
join_sp_n100k_e8: a100k_8.join(" ")
join_sp_n100k_e40: a100k_40.join(" ")
# separator "\n" (newline)
join_nl_n100_e1: a100_1.join("\n")
join_nl_n100_e8: a100_8.join("\n")
join_nl_n100_e40: a100_40.join("\n")
join_nl_n1k_e1: a1k_1.join("\n")
join_nl_n1k_e8: a1k_8.join("\n")
join_nl_n1k_e40: a1k_40.join("\n")
join_nl_n100k_e1: a100k_1.join("\n")
join_nl_n100k_e8: a100k_8.join("\n")
join_nl_n100k_e40: a100k_40.join("\n")