Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- require 'benchmark/memory'
- #meu teste
- def mydelete(a)
- i = 0
- while(i < a.size)
- if a[i] == 2
- a.delete_at(i)
- else
- i += 1
- end
- end
- return a
- end
- #teste do val
- def valdelete(a)
- ary2 = []
- a.each_with_index do |e, i|
- if e == 2
- ary2 << i
- end
- end
- ary2.reverse_each do |i|
- a.delete_at(i)
- end
- return a
- end
- # benchmark setup
- def benchmark(a)
- puts "Benchmark.bmbm"
- Benchmark.bmbm do |x|
- x.report("My delete") {mydelete(a)}
- x.report("Val delete") {valdelete(a)}
- end
- puts "Benchmark.memory"
- Benchmark.memory do |x|
- x.report("My delete") {mydelete(a)}
- x.report("Val delete") {valdelete(a)}
- end
- end
- benchmark( [2, 5, 2, 7, 2, 9])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement