Sha256: b74effd4a91310b6a030885a313455ea0c47ae4f861c0030fdbee5bc55570b53

Contents?: true

Size: 1.17 KB

Versions: 54

Compression:

Stored size: 1.17 KB

Contents

#!/usr/bin/env ruby

require "timeout"

args = {}
ARGV.each do |arg|
  if match = arg.match(/^tmpfile=(.+)$/)
    args["tmpfile"] = match[1]
  else
    raise "Unknown argument: '#{arg}'."
  end
end

raise "No 'tmpfile' given in arguments." if !args["tmpfile"]

#8 kb string.
str = ("0" * 1024) * 8
strl = str.length

count = 0
time_begin = Time.now.to_f

puts "Starting to write file."
begin
  Timeout.timeout(4) do
    File.open(args["tmpfile"], "w") do |fp|
      fp.sync = true
      
      loop do
        fp.write(str)
        count += strl
      end
    end
  end
rescue Timeout::Error
  #ignore
end

secs = Time.now.to_f - time_begin
mb_sec = ((count / secs) / 1024) / 1024

puts "#{mb_sec.round(2)} mb/s in #{secs.round(1)} seconds."


puts "Starting to read the file again."
count = 0
time_begin = Time.now.to_f

begin
  Timeout.timeout(4) do
    File.open(args["tmpfile"], "r") do |fp|
      loop do
        read = fp.read(4096)
        count += read.length
      end
    end
  end
rescue Timeout::Error
  #ignore
end

secs = Time.now.to_f - time_begin
mb_sec = ((count / secs) / 1024) / 1024

puts "#{mb_sec.round(2)} mb/s in #{secs.round(1)} seconds."

File.unlink(args["tmpfile"])

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
knjrbfw-0.0.116 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.115 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.114 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.113 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.111 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.110 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.109 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.108 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.107 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.105 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.104 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.103 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.102 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.101 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.100 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.99 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.98 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.97 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.96 lib/knj/scripts/speed_test.rb
knjrbfw-0.0.95 lib/knj/scripts/speed_test.rb