File: string.rb

package info (click to toggle)
ruby-protocol-http 0.23.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 472 kB
  • sloc: ruby: 2,794; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 500 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

def generator
	100000.times do |i|
		yield "foo #{i}"
	end
end

def consumer_without_clear
	buffer = String.new
	generator do |chunk|
		buffer << chunk
	end
	return nil
end

def consumer_with_clear
	buffer = String.new
	generator do |chunk|
		buffer << chunk
		chunk.clear
	end
	return nil
end

require 'benchmark'

Benchmark.bm do |x|
	x.report("consumer_with_clear") do
		consumer_with_clear
		GC.start
		
	end
	
	x.report("consumer_without_clear") do
		consumer_without_clear
		GC.start
	end
end