Created
December 16, 2024 01:29
-
-
Save paderinandrey/8a5bfa1df32218d3e2cbe951e26a575d to your computer and use it in GitHub Desktop.
TH: ruby-c11y-hw1
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
# Генерация файлов для примера | |
files = 5.times.map do |i| | |
filename = "file_#{i}.txt" | |
File.open(filename, 'w') { |f| f.puts(Array.new(100_000) { "Line from #{filename}" }) } | |
filename | |
end | |
require 'parallel' | |
def process_files_with_parallel(files) | |
Parallel.each(files, in_processes: files.size) do |file| | |
File.open(file, 'r') do |f| | |
f.each_line { |line| puts line } | |
end | |
end | |
end | |
start_time = Time.now | |
process_files_with_parallel(files) | |
end_time = Time.now | |
puts "Время выполнения: #{end_time - start_time} секунд" | |
# Время выполнения: 1.535472 секунд |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment