Skip to content

Instantly share code, notes, and snippets.

@alco
Created July 15, 2014 11:33
Show Gist options
  • Save alco/330d7b8a601bfed057dc to your computer and use it in GitHub Desktop.
Save alco/330d7b8a601bfed057dc to your computer and use it in GitHub Desktop.
Benchfella.start duration: 1.0, format: :machine, verbose: true
defmodule StringSlice do
use Benchfella
Enum.each([100, 1000, 10000], fn n ->
@str String.duplicate("hello world", n)
@len String.length(@str)
bench "negative both #{n}" do
String.slice(@str, [email protected])
end
end)
end
Benchfella.start duration: 1.0, format: :machine, verbose: true
defmodule StringSlice do
use Benchfella
Enum.each([100, 1000, 10000], fn n ->
@str String.duplicate("hello world", n)
@len String.length(@str)
bench "negative left #{n}" do
String.slice(@str, -div(@len,2)..@len)
end
end)
end
Benchfella.start duration: 1.0, format: :machine, verbose: true
defmodule StringSlice do
use Benchfella
Enum.each([100, 1000, 10000], fn n ->
@str String.duplicate("hello world", n)
@len String.length(@str)
bench "negative right #{n}" do
String.slice(@str, 8..-div(@len, 2))
end
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment