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