Class: WisconsinBenchmark::ArrayGenerator
- Inherits:
-
Object
- Object
- WisconsinBenchmark::ArrayGenerator
- Defined in:
- lib/wisconsin-benchmark/array_generator.rb
Overview
Array generator
Instance Method Summary collapse
-
#initialize(size) ⇒ ArrayGenerator
constructor
A new instance of ArrayGenerator.
-
#inspect ⇒ String
summary of the object.
-
#string4 ⇒ Array<String>
Create a cyclic repeated string array, string4.
-
#stringu1 ⇒ Array<String>
Create a randomly distributed string array, stringu1.
-
#stringu2 ⇒ Array<String>
Create a sequencial string array, stringu2.
-
#unique1 ⇒ Numo::UInt32
Create a random/unique record array 0…size in range.
-
#unique2 ⇒ Numo::UInt32
Create a sequential record array as 0…size.
Constructor Details
#initialize(size) ⇒ ArrayGenerator
Returns a new instance of ArrayGenerator.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/wisconsin-benchmark/array_generator.rb', line 4 def initialize(size) if size <= 1000 then @generator = 279; @prime = 1009 elsif size <= 10000 then @generator = 2969; @prime = 10007 elsif size <= 100000 then @generator = 21395; @prime = 100003 elsif size <= 1000000 then @generator = 2107; @prime = 1000003 elsif size <= 10000000 then @generator = 211; @prime = 10000019 elsif size <= 100000000 then @generator = 21; @prime = 100000007 else raise "too many rows requested #{size}" end @size = size end |
Instance Method Details
#inspect ⇒ String
summary of the object.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wisconsin-benchmark/array_generator.rb', line 21 def inspect <<~STR <#{self.class} ( size=#{@size}, unique1=#{inspect_array(@unique1)}, unique2=#{inspect_array(@unique2)}, stringu1=#{inspect_array(@stringu1)}, stringu2=#{inspect_array(@stringu2)}, string4=#{inspect_array(@string4)} )> STR end |
#string4 ⇒ Array<String>
Create a cyclic repeated string array, string4.
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/wisconsin-benchmark/array_generator.rb', line 120 def string4 @string4 ||= begin warn 'Generating string4' trailer = 'x' * 48 array = %w[AAAA HHHH OOOO VVVV].map { _1 << trailer } a = @size.times.map { |i| array[i % 4] } Arrow::StringArray.new(a) end end |
#stringu1 ⇒ Array<String>
Create a randomly distributed string array, stringu1.
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/wisconsin-benchmark/array_generator.rb', line 76 def stringu1 @stringu1 ||= begin warn 'Generating stringu1' trailer = 'x' * 45 a = unique1.to_a.map do |i| str = i.to_s(26).tr('0-9a-p', 'A-Z') ('A' * (7 - str.size)) << str << trailer end Arrow::StringArray.new(a) end end |
#stringu2 ⇒ Array<String>
Create a sequencial string array, stringu2.
99 100 101 102 103 104 105 106 107 |
# File 'lib/wisconsin-benchmark/array_generator.rb', line 99 def stringu2 @stringu2 ||= begin warn 'Generating stringu2' trailer = 'x' * 45 a = (('A' * 7)..).take(@size).map { _1 << trailer } Arrow::StringArray.new(a) end end |
#unique1 ⇒ Numo::UInt32
Create a random/unique record array
0...size in range
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wisconsin-benchmark/array_generator.rb', line 39 def unique1 @unique1 ||= begin warn 'Generating unique1' seed = @generator ary = @size.times.map do seed = rand(seed) seed - 1 end Numo::UInt32.new(@size).store(ary) end end |
#unique2 ⇒ Numo::UInt32
Create a sequential record array as 0…size.
56 57 58 59 60 61 62 |
# File 'lib/wisconsin-benchmark/array_generator.rb', line 56 def unique2 @unique2 ||= begin warn 'Generating unique2' Numo::UInt32.new(@size).seq end end |