Skip to content

Instantly share code, notes, and snippets.

@sho-h
Created February 18, 2018 06:51
Show Gist options
  • Save sho-h/5b5d0ffec652cd184115d810ae097563 to your computer and use it in GitHub Desktop.
Save sho-h/5b5d0ffec652cd184115d810ae097563 to your computer and use it in GitHub Desktop.
require "tempfile"
data = "test"
[:flush, :fsync, :fdatasync].each do |method|
puts "---- #{method} ----"
res = []
10.times do
Tempfile.open("testtmpfile") do |f|
before = Time.now
10000.times do |i|
f.print(data)
f.send(method)
end
res << (Time.now - before)
end
end
puts "#{method}: #{res.inject(0) {|res, t| res + t } / res.length} sec"
end
# ---- flush ----
# flush: 0.06868516690000001 sec
# ---- fsync ----
# fsync: 3.1406286125999996 sec
# ---- fdatasync ----
# fdatasync: 3.1831921884 sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment