<commit_before>require 'coderay'
require 'benchmark'

N = 10
$code = 'foo(Foo[:foo, /foo/m]); ' * 500
Benchmark.bm 15 do |bm|
	bm.report 'loading' do
		CodeRay::Scanners.load :ruby
		CodeRay::Encoders.load :div
	end
	bm.report 'CodeRay.encode' do N.times do
		CodeRay.encode($code, :ruby, :div)
	end end
	bm.report 'Direct' do N.times do
		CodeRay::Encoders::Div.new.encode_tokens(
			CodeRay::Scanners::Ruby.new($code).tokenize
		)
	end end
	bm.report 'Semi-cached' do
		encoder = CodeRay::Encoders::Div.new
		N.times do
			encoder.encode $code, :ruby
		end
	end
	bm.report 'Fully cached' do
		scanner = CodeRay::Scanners::Ruby.new('')
		encoder = CodeRay::Encoders::Div.new<commit_msg>Made caching demo more expressing.<commit_after>require 'coderay'
require 'benchmark'

N = 1000
$code = 'snoo Snoo ' * 10
Benchmark.bm 15 do |bm|
	bm.report 'loading' do
		CodeRay::Scanners.load :ruby
		CodeRay::Encoders.load :div
	end
	bm.report 'CodeRay.encode' do N.times do
		CodeRay.encode($code, :ruby, :div)
	end end
	bm.report 'Direct' do N.times do
		CodeRay::Encoders::Div.new.encode_tokens(
			CodeRay::Scanners::Ruby.new($code).tokenize
		)
	end end
	bm.report 'Semi-cached' do
		encoder = CodeRay::Encoders::Div.new
		N.times do
			encoder.encode $code, :ruby
		end
	end
	bm.report 'Fully cached' do
		scanner = CodeRay::Scanners::Ruby.new('')
		encoder = CodeRay::Encoders::Div.new
{'fraction_non_alphanumeric': 0.1447178002894356, 'fraction_numerical': 0.01085383502170767, 'mean_word_length': 4.319230769230769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6134666', 'n_tokens_mistral': 595, 'n_tokens_neox': 533, 'n_words': 125}