VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /proc/self/root/var/lib/gems/2.5.0/gems/posix-spawn-0.3.9/bin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/var/lib/gems/2.5.0/gems/posix-spawn-0.3.9/bin/posix-spawn-benchmark
#!/usr/bin/env ruby
#/ Usage: posix-spawn-benchmark [-n <count>] [-m <mem-size>]
#/ Run posix-spawn (Ruby extension) benchmarks and report to standard output.
#/
#/ Options:
#/   -n, --count=NUM         total number of processes to spawn.
#/   -m, --mem-size=MB       RES size to bloat to before performing benchmarks.
#/   -g, --graph             benchmark at 10MB itervals up to RES and graph results.
#/
#/ Benchmarks run with -n 1000 -m 100 by default.
require 'optparse'
require 'posix-spawn'
require 'benchmark'
include Benchmark

allocate   = 100 * (1024 ** 2)
iterations = 1_000
graphmode  = false
ARGV.options do |o|
  o.set_summary_indent('  ')
  o.on("-n", "--count=num")   { |val| iterations = val.to_i }
  o.on("-m", "--mem-size=MB") { |val| allocate   = val.to_i * (1024 ** 2) }
  o.on("-g", "--graph")       { graphmode = true }
  o.on_tail("-h", "--help")   { exec "grep ^#/ <'#{__FILE__}' |cut -c4-" }
  o.parse!
end

if graphmode
  bloat = []
  data  = {}
  chunk = allocate / 10
  max   = 0

  10.times do
    puts "allocating #{chunk / (1024 ** 2)}MB (#{(bloat.size+1) * chunk / (1024 ** 2)}MB total)"
    bloat << ('x' * chunk)
    # size = bloat.size / (1024 ** 2)

    %w[ fspawn pspawn ].each do |type|
      print " - benchmarking #{type}... "
      time = Benchmark.realtime do
        iterations.times do
          pid = POSIX::Spawn.send(type, 'true')
          Process.wait(pid)
        end
      end
      puts "done (#{time})"

      data[type] ||= []
      data[type] << time
      max = time if time > max
    end
  end

  max = max < 0.5 ? (max * 10).round / 10.0 : max.ceil
  minmb, maxmb = chunk/(1024**2), allocate/(1024**2)
  series = %w[ fspawn pspawn ].map{|name| data[name].map{|d| "%.2f" % d }.join(',') }

  chart = {
    :chs  => '900x200',
    :cht  => 'bvg', # grouped vertical bar chart
    :chtt => "posix-spawn-benchmark --graph --count #{iterations} --mem-size #{maxmb} (#{RUBY_PLATFORM})",

    :chf  => 'bg,s,f8f8f8', # background
    :chbh => 'a,5,25', # 25px between bar groups

    :chd  => "t:#{series.join('|')}", # data
    :chds => "0,#{max}", # scale
    :chdl => 'fspawn (fork+exec)|pspawn (posix_spawn)', # legend
    :chco => '1f77b4,ff7f0e', # colors

    :chxt => 'x,y',
    :chxr => "1,0,#{max},#{max/5}", # y labels up to max time
    :chxs => '1N** secs', # y labels are +=' secs'
    :chxl => "0:|#{minmb.step(maxmb, maxmb/10).map{ |mb| "#{mb} MB"}.join('|')}", # x bucket labels
  }

  url  = "https://chart.googleapis.com/chart?"
  url += chart.map do |key, val|
    "#{key}=#{val.gsub(' ','%20').gsub('(','%28').gsub(')','%29').gsub('+','%2B')}"
  end.join('&')
  url += '#.png'

  puts url

  exit!
end

puts "benchmarking fork/exec vs. posix_spawn over #{iterations} runs" +
     " at #{allocate / (1024 ** 2)}M res"

# bloat the process
bloat = 'x' * allocate

# run the benchmarks
bm 40 do |x|
  x.report("fspawn (fork/exec):") do
    iterations.times do
      pid = POSIX::Spawn.fspawn('true')
      Process.wait(pid)
    end
  end
  x.report("pspawn (posix_spawn):") do
    iterations.times do
      pid = POSIX::Spawn.pspawn('true')
      Process.wait(pid)
    end
  end
  if Process.respond_to?(:spawn)
    x.report("spawn (native):") do
      iterations.times do
        pid = Process.spawn('true')
        Process.wait(pid)
      end
    end
  end
end

VaKeR 2022