File: graphql.rb

package info (click to toggle)
ruby-batch-loader 2.0.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 284 kB
  • sloc: ruby: 783; makefile: 6; sh: 4
file content (28 lines) | stat: -rw-r--r-- 689 bytes parent folder | download | duplicates (3)
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

# Usage: ruby spec/benchmarks/graphql.rb && open tmp/stack.html

require 'ruby-prof'
require "graphql"

require_relative "../../lib/batch_loader"
require_relative "../fixtures/models"
require_relative "../fixtures/graphql_schema"

iterations = Array.new(2_000)

iterations.each_with_index do |_, i|
  user = User.save(id: i)
  Post.save(user_id: user.id)
end

query = "{ posts { user { id } } }"

RubyProf.measure_mode = RubyProf::WALL_TIME
RubyProf.start

GraphqlSchema.execute(query) # 0.45, 0.52, 0.47 sec

result = RubyProf.stop
stack_printer = RubyProf::CallStackPrinter.new(result)
File.open("tmp/stack.html", 'w') { |file| stack_printer.print(file) }