Created
December 26, 2018 17:45
-
-
Save hartator/46b0791e8532292c5a46bc78e4385e37 to your computer and use it in GitHub Desktop.
Source code for Benchmark v2: Deep directory structure vs. flat directory structure to store millions of files on ext4 article (https://medium.com/@hartator/benchmark-deep-directory-structure-vs-flat-directory-structure-to-store-millions-of-files-on-ext4-cac1000ca28)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest' | |
require 'benchmark' | |
require 'open-uri' | |
keys = [] | |
10_000_000.times do | |
keys << Digest::MD5.hexdigest(rand.to_s) | |
end | |
body = open("https://serpapi.com/samples/3.json").read; nil; | |
`rm -rf /root/files/*` | |
FileUtils.mkdir_p "dir_flat" | |
sleep 100 | |
puts Benchmark.measure { | |
keys.each do |key| | |
File.write "./dir_flat/#{key}", body | |
end | |
} | |
sleep 100 | |
puts Benchmark.measure { | |
keys.each do |key| | |
File.read "./dir_flat/#{key}" | |
end | |
} | |
`rm -rf /root/files/*` | |
FileUtils.mkdir_p "dir_deep" | |
sleep 100 | |
puts Benchmark.measure { | |
keys.each do |key| | |
dir_path = "./dir_deep/#{key[0..1]}/#{key[2..3]}/" | |
FileUtils.mkdir_p dir_path | |
end | |
} | |
sleep 100 | |
puts Benchmark.measure { | |
keys.each do |key| | |
dir_path = "./dir_deep/#{key[0..1]}/#{key[2..3]}/" | |
File.write dir_path + key, body | |
end | |
} | |
sleep 100 | |
puts Benchmark.measure { | |
keys.each do |key| | |
dir_path = "./dir_deep/#{key[0..1]}/#{key[2..3]}/" | |
File.read dir_path + key | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment