|
#/usr/bin/env |
|
# **Note** this program require the benchmark-ips gem, installed with: |
|
# gem install benchmark-ips |
|
# |
|
# To run, from the root of the Test Kitchen codebase: |
|
# ruby -Ilib benchmark.rb |
|
# |
|
require "benchmark" |
|
require "benchmark/ips" |
|
require "kitchen/transport/winrm" |
|
|
|
t = Kitchen::Transport::Winrm.new(kitchen_root: "./tmp").finalize_config!(OpenStruct.new(name: "coolbeans")) |
|
c = t.connection(hostname: "127.0.0.1", username: "vagrant", password: "vagrant") |
|
|
|
# yank out the raw CommandExecutor |
|
executor = c.send(:session) |
|
# yank out the WinRMWebService from the executor |
|
vanilla = executor.instance_variable_get(:@service) |
|
|
|
# with CMD we can get closer to 8K (max command line size), but this |
|
# will be Base64-encoded for the Powershell script, so we'll go with 2K |
|
output = ("." * 2000).freeze |
|
|
|
# start fresh new files |
|
%w[executor-cmd vanilla-cmd executor-ps1 vanilla-ps1].each do |file| |
|
executor.run_cmd("echo START > %TEMP%\\#{file}.txt") |
|
end |
|
|
|
puts "## Profiling CMD and Powershell script commands (uploading a file)\n\n" |
|
|
|
Benchmark.ips do |x| |
|
x.time = 20 |
|
x.warmup = 5 |
|
|
|
x.report("cmd_executor") do |
|
executor.run_cmd("echo #{output} >> %TEMP%\\executor-cmd.txt") |
|
end |
|
|
|
x.report("cmd_vanilla") do |
|
vanilla.run_cmd("echo #{output} >> %TEMP%\\vanilla-cmd.txt") |
|
end |
|
|
|
x.report("ps1_executor") do |
|
executor.run_powershell_script(%{Add-Content $env:Temp\\executor-ps1.txt "#{output}"}) |
|
end |
|
|
|
x.report("ps1_vanilla") do |
|
vanilla.run_powershell_script(%{Add-Content $env:Temp\\vanilla-ps1.txt "#{output}"}) |
|
end |
|
|
|
x.compare! |
|
end |