Skip to content

Instantly share code, notes, and snippets.

@pocke
Created November 6, 2019 12:46
Show Gist options
  • Save pocke/4b164decc432461098bf2bf9807c4009 to your computer and use it in GitHub Desktop.
Save pocke/4b164decc432461098bf2bf9807c4009 to your computer and use it in GitHub Desktop.
require 'pathname'
require 'fileutils'
LOG_PATH = Pathname('/tmp/vimbench.log')
RE = /(\d+\.\d+)\s*\d+\.\d+:\s*--- N?VIM STARTED ---/
N = 10
def prepare
FileUtils.rm LOG_PATH if LOG_PATH.exist?
FileUtils.touch LOG_PATH
q = Queue.new
th = Thread.new do
IO.popen('tail -f /tmp/vimbench.log') do |io|
io.each_line do |line|
q << Object.new if line =~ RE
end
end
end
return q, th
end
def clear(q, th)
q.close
th.kill
end
def stats
content = LOG_PATH.read
content.scan(RE).flatten.map(&:to_f)
end
def format(stats)
<<~END
results: #{stats.join ' '}
average: #{stats.sum / stats.size}
END
end
q, th = prepare
N.times do
pid = spawn("vim --startuptime #{LOG_PATH}")
q.pop
Process.kill :SIGTERM, pid
end
clear q, th
vimrc_stat = stats
q, th = prepare
# default
N.times do
pid = spawn("vim -u DEFAULTS --startuptime #{LOG_PATH}")
q.pop
Process.kill :SIGTERM, pid
end
clear q, th
no_vimrc_stat = stats
system 'reset'
puts <<~END
with vimrc
#{format vimrc_stat}
no vimrc
#{format no_vimrc_stat}
#{sprintf("%.3f", vimrc_stat.sum / no_vimrc_stat.sum)}x slower your Vim than the default.
END
FileUtils.rm LOG_PATH
@pocke
Copy link
Author

pocke commented Nov 6, 2019

with vimrc
results: 253.252 253.791 245.451 252.825 253.659 243.336 242.436 248.03 243.538 276.004
average: 251.2322


no vimrc
results: 14.158 8.689 21.326 12.332 10.666 13.07 13.095 11.285 9.083 14.953
average: 12.8657


19.527x slower your Vim than the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment