Skip to content

Instantly share code, notes, and snippets.

@aaronjensen
Created January 7, 2015 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronjensen/46bff917f3dff3a3e851 to your computer and use it in GitHub Desktop.
Save aaronjensen/46bff917f3dff3a3e851 to your computer and use it in GitHub Desktop.
ready "codepoints" do
before do
@str = "a" * 30 + "x"
end
go "index many matches" do
index = @str.index("a")
while index
index = @str.index("a", index + 1)
end
end
go "codepoints many matches" do
points = @str.codepoints
i = 0
length = points.length
while i < length
points[i] == 97
i += 1
end
end
go "index one match" do
index = @str.index("x")
while index
index = @str.index("x", index + 1)
end
end
go "codepoints one match" do
points = @str.codepoints
i = 0
length = points.length
while i < length
points[i] == 120
i += 1
end
end
end
codepoints index many matches
Baseline: | X------|
Current: | X------|
0 4.969 us
codepoints codepoints many matches
Baseline: | X---------- |
Current: | X--------|
0 1.837 us
codepoints index one match
Baseline: | X------------|
Current: | X-------- |
0 337.891 ns
codepoints codepoints one match
Baseline: | X---|
Current: | X----|
0 1.708 us
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment