Sha256: 117dfde448ce27cb0fbe8b0e5da015ef75aba337b77730eef324b1b4653179a9

Contents?: true

Size: 792 Bytes

Versions: 32

Compression:

Stored size: 792 Bytes

Contents

#!/usr/bin/env ruby

require_relative 'memory'

string = nil

measure_memory("Initial allocation") do
	string = "a" * 5*1024*1024
	string.freeze
end # => 5.0 MB

measure_memory("Byteslice from start to middle") do
	# Why does this need to allocate memory? Surely it can share the original allocation?
	x = string.byteslice(0, string.bytesize / 2)
end # => 2.5 MB

measure_memory("Byteslice from middle to end") do
	string.byteslice(string.bytesize / 2, string.bytesize)
end # => 0.0 MB

measure_memory("Slice! from start to middle") do
	string.dup.slice!(0, string.bytesize / 2)
end # => 7.5 MB

measure_memory("Byte slice into two halves") do
	head = string.byteslice(0, string.bytesize / 2) # 2.5 MB
	remainder = string.byteslice(string.bytesize / 2, string.bytesize) # Shared
end # 2.5 MB

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
async-io-1.27.2 examples/allocations/byteslice.rb
async-io-1.27.1 examples/allocations/byteslice.rb
async-io-1.27.0 examples/allocations/byteslice.rb
async-io-1.26.0 examples/allocations/byteslice.rb
async-io-1.25.0 examples/allocations/byteslice.rb
async-io-1.24.0 examples/allocations/byteslice.rb
async-io-1.23.3 examples/allocations/byteslice.rb
async-io-1.23.1 examples/allocations/byteslice.rb
async-io-1.23.0 examples/allocations/byteslice.rb
async-io-1.22.0 examples/allocations/byteslice.rb
async-io-1.21.0 examples/allocations/byteslice.rb
async-io-1.20.0 examples/allocations/byteslice.rb
async-io-1.18.5 examples/allocations/byteslice.rb
async-io-1.18.4 examples/allocations/byteslice.rb
async-io-1.18.3 examples/allocations/byteslice.rb
async-io-1.18.2 examples/allocations/byteslice.rb
async-io-1.18.1 examples/allocations/byteslice.rb
async-io-1.17.2 examples/allocations/byteslice.rb
async-io-1.17.1 examples/allocations/byteslice.rb
async-io-1.16.4 examples/allocations/byteslice.rb