Created
April 3, 2015 12:35
-
-
Save mindreframer/b3dffd6b26dd78a1e337 to your computer and use it in GitHub Desktop.
Benchmark Static Site Generators
This file contains hidden or 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
#!/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