Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kostya

kostya/1.cr Secret

Last active August 29, 2015 13:57
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 kostya/c1748e5dde4aefa4cb14 to your computer and use it in GitHub Desktop.
Save kostya/c1748e5dde4aefa4cb14 to your computer and use it in GitHub Desktop.
strange (crystal lang https://github.com/manastech/crystal)
def foo(n)
String.new_with_capacity(n * 4 + 10) do |buf|
bufc = 0
bar(n) do |byte|
buf[bufc] = byte
bufc += 1
end
bufc
end
end
def bar(n)
n.times do
yield 33_u8
yield 34_u8
yield 35_u8
yield 36_u8
end
case rand(3)
when 1
yield 37_u8
yield 38_u8
when 2
yield 39_u8
yield 33_u8
yield 33_u8
end
end
t = Time.now
s = 0_u64
1000.times{ |i| res = foo(100000); s += res[i] }
p s
p Time.now - t
def foo(n)
String.new_with_capacity(n * 4 + 10) do |buf|
bufc = 0
bar(n) do |byte|
buf[bufc] = byte
bufc += 1
end
bufc
end
end
def bar(n)
n.times do
yield 33_u8
yield 34_u8
yield 35_u8
yield 36_u8
end
case rand(3)
when 1
yield 37_u8
yield 38_u8
when 2
yield 39_u8
yield 33_u8
#yield 33_u8
end
end
t = Time.now
s = 0_u64
1000.times{ |i| res = foo(100000); s += res[i] }
p s
p Time.now - t
@kostya
Copy link
Author

kostya commented Mar 8, 2014

./bin/crystal 1.cr --release && ./1
34500
1.4392
./bin/crystal 2.cr --release && ./2
34500
0.309147

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