Class: WisconsinBenchmark::ArrayGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/wisconsin-benchmark/array_generator.rb

Overview

Array generator

Instance Method Summary collapse

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

#inspectString

summary of the object.

Returns:

  • (String)

    return class name, size and value range of each arrays.



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

#string4Array<String>

Create a cyclic repeated string array, string4.

Examples:

['AAAAxxxxx ... ', 'HHHHxxxxx ... ', 'OOOOxxxxx ... ', 'VVVVxxxxx ...', ... ]

Returns:

  • (Array<String>)

    cyclic repeating array of strings.

    • Each string is 52 bytes.

    • string is one of [‘AAAA’, ‘HHHH’, ‘OOOO’, ‘VVVV’].

    • string is ‘x’ * 48

    • four strings are repeated.



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

#stringu1Array<String>

Create a randomly distributed string array, stringu1.

Examples:

['AAAAAFRxxxxx ... ', 'AAAABJVxxxxx ... ', 'AAAABBMxxxxx ... ', ... ]

Returns:

  • (Array<String>)

    array of generated randomly distributed distinct strings.

    • Each string is 52 bytes.

    • string is converted string from numbers in randomly distributed unique1. The numbers are converted to n-adic string mapped for ‘A-Z’. => ‘AAAAAAA’, 2 => ‘AAAAAAB’, … 26 => ‘AAAAAAZ’, 27 => ‘AAAAABA’, …

    • string is ‘x’ * 45



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

#stringu2Array<String>

Create a sequencial string array, stringu2.

Examples:

['AAAAAAAxxxxx ... ', 'AAAAAABxxxxx ... ', 'AAAAAACxxxxx ... ', ... ]

Returns:

  • (Array<String>)

    sequential array of strings.

    • Each string is 52 bytes.

    • string is sequential string consists of ‘A’..‘Z’ started from ‘AAAAAAA’.

    • string is ‘x’ * 45



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

#unique1Numo::UInt32

Create a random/unique record array

0...size in range

Returns:

  • (Numo::UInt32)

    array of attribute :unique1.



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

#unique2Numo::UInt32

Create a sequential record array as 0…size.

Returns:

  • (Numo::UInt32)

    array of attribute :unique2.



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