While looking for performance bottlenecks i stumbled into this which is quite surprising.
@some_string "1632767814.9532351 00 0 0 1 0 0 0 0 0 0 0 0 0 0 00 00 0 00 00 00 00 00 0e 01 14 3c 3c 96 20 99 ba 1e 10 80 93 a7 1d 00 00 01 00 00 00 00 00 00 00 00 00 00 00 0 0 0"
def bench_string_split_trim(n) do
fun1 = fn ->
Enum.map(1..n, fn(_x) ->
String.split(@some_string, " ", trim: true) end)
end
fun2 = fn ->
Enum.map(1..n, fn(_x) ->
String.split(@some_string, " ") |> Enum.filter(fn(x) -> x != "" end) end)
end
Benchee.run(
%{
"vanilla" => fun1,
"filter" => fun2,
},
formatters: [
{Benchee.Formatters.HTML, file: "samples_output/my.html"},
Benchee.Formatters.Console
]
)
end
Replacing trim: true with filter more than doubles the performance; just my 2 cents, might be handy for someone out there.
cheers!






















