File: jsonb_accessor_performance_spec.rb

package info (click to toggle)
ruby-jsonb-accessor 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 316 kB
  • sloc: ruby: 1,819; makefile: 10; sh: 5
file content (28 lines) | stat: -rw-r--r-- 840 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
# frozen_string_literal: true

require "benchmark"
require "spec_helper"

RSpec.describe "Jsonb Accessor Performace" do
  context "initializing objects from the database" do
    before do
      1000.times do
        Product.create(
          string_type: "static string",
          integer_type: (1..60_000).to_a.sample,
          boolean_type: [true, false].sample,
          float_type: rand,
          time_type: Time.now,
          date_type: Date.today
        )
      end
    end

    it "is of reasonable performance against non-jsonb records" do
      static_time = Benchmark.realtime { StaticProduct.all.to_a }
      jsonb_time = Benchmark.realtime { Product.all.to_a }
      # it shouldn't even be 0.1 seconds slower to fetch and instantiate 1000 records
      expect((static_time - jsonb_time).abs).to be < 0.1
    end
  end
end