Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ruby blocks vs JS callbacks
function benchmark(cb) {
const start_time = 12345;
const result = cb('some message');
console.log("the return value of cb was: ", result);
const end_time = 12456;
return end_time - start_time
const time_taken = benchmark((message) => {
let s = 'asdf';
for (let i = 0; i < 100000; i++) {
s[2] = 'z';
console.log("the message:", message)
return "some result value";
def benchmark
start_time =
result = yield 'some message'
puts "the return value of the block: #{result}"
end_time =
end_time - start_time
long_string = 'apple'*10000000
running_time = benchmark do |msg|
puts "the message: #{msg}"
"some result value"
puts "it took: #{running_time}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.