Skip to content

Instantly share code, notes, and snippets.

@quyen91
Forked from mindreframer/create_files.rb
Created September 30, 2018 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quyen91/a4b4000780af06bab4c5d43d39753514 to your computer and use it in GitHub Desktop.
Save quyen91/a4b4000780af06bab4c5d43d39753514 to your computer and use it in GitHub Desktop.
Benchmark Static Site Generators
#!/usr/bin/env ruby -wKU
require 'yaml'
class Generator
def run
300.times do |i|
File.open(name(i), 'w') do |f|
f.puts Article.new.content
end
end
end
def name(i)
filename = 'temp' + "#{(i+1).to_s.rjust(4, '0')}" + '.md'
path = "collections/article/#{filename}"
end
end
class Article
require 'securerandom'
def content
[metadata, body].join("\n")
end
def metadata
date = Date.new( rand(4) + 2012, rand(12)+1, rand(25)+1)
{
title: random_string,
date: date,
published: true,
tags: ['Example', 'Markdown'],
}.to_yaml
end
def body
(rand(15) + 4).times.map do |i|
sentence
end.join("\n")
end
def random_string
SecureRandom.hex.tap do |s|
s.gsub!(/\d/, '')
end
end
def sentence
[].tap do |a|
rand(13).times do
a.push random_string
end
end.join(" ") + "."
end
end
#puts Article.new.content
Generator.new.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment