summaryrefslogtreecommitdiff
path: root/benchmark/require_thread.yml
blob: 0c632571064c59cedbab970fb5363149aaa6c673 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
prelude: |
  require "fileutils"

  def prepare
    num_files = 10000

    basename = File.dirname($0)
    data_dir = File.join(basename, "bm_require.data")

    # skip if all of files exists
    if File.exist?(File.join(data_dir, "c#{num_files}.rb"))
      return
    end

    FileUtils.mkdir_p(data_dir)

    1.upto(num_files) do |i|
      File.write("#{data_dir}/c#{i}.rb", "class C#{i}\n""end\n")
    end
  end

  prepare
benchmark:
  require_thread: |
    $:.push File.join(File.dirname(__FILE__), "bm_require.data")

    i=0
    t = Thread.new do
      while true
        i = i+1 # dummy loop
      end
    end

    1.upto(100) do |i|
      require "c#{i}"
    end

    $:.pop
    t.kill
loop_count: 1