Skip to content

Instantly share code, notes, and snippets.

@Nezteb
Created June 24, 2025 20:51
Show Gist options
  • Save Nezteb/7b8d1061e3ea1739e4de1b9307c9d01b to your computer and use it in GitHub Desktop.
Save Nezteb/7b8d1061e3ea1739e4de1b9307c9d01b to your computer and use it in GitHub Desktop.
# Test with different integer sizes
small_int = 42
medium_int = 123_456
large_int = 9_876_543_210
small_str = "42"
medium_str = "123456"
large_str = "9876543210"
Benchee.run(
%{
"Small Int -> String" => fn -> Integer.to_string(small_int) end,
"Small String -> Int" => fn -> String.to_integer(small_str) end,
"Medium Int -> String" => fn -> Integer.to_string(medium_int) end,
"Medium String -> Int" => fn -> String.to_integer(medium_str) end,
"Large Int -> String" => fn -> Integer.to_string(large_int) end,
"Large String -> Int" => fn -> String.to_integer(large_str) end
},
time: 5,
memory_time: 2,
warmup: 2
)
@Nezteb
Copy link
Author

Nezteb commented Jun 25, 2025

Comparison:
Small      Int    -> String    6.20 M
Medium     Int    -> String    5.98 M    - 1.04x slower     +  5.90 ns
Large      Int    -> String    5.51 M    - 1.13x slower     + 20.31 ns
Small      String -> Int       4.93 M    - 1.26x slower     + 41.71 ns
Medium     String -> Int       6.07 M    - 1.02x slower     +  3.30 ns
Large      String -> Int       5.67 M    - 1.09x slower     + 15.09 ns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment