Rakefile in LittleWeasel-5.0.10 vs Rakefile in LittleWeasel-5.0.11
- old
+ new
@@ -1,12 +1,13 @@
-# frozen_string_literal: true
+# frozen_string_literal: false
require 'active_support/core_ext/object/try.rb'
require 'active_support/inflector'
require 'benchmark/ips'
require 'bundler/gem_tasks'
require 'pry'
+require 'rubocop/rake_task'
require_relative 'lib/LittleWeasel'
require_relative 'spec/support/file_helpers'
require_relative 'spec/support/general_helpers'
@@ -28,11 +29,11 @@
#
# Tasks related to the #word_results API
namespace 'word_results' do
- # Creates a dictionary from a file on disk
+ desc 'Creates a dictionary from a file on disk - perform basic word search results operations'
task :basic do
LittleWeasel.configure do |config|
# TODO: Configure as needed here.
end
@@ -65,11 +66,11 @@
puts "LittleWeasel task word_results:basic not loaded: #{e.message}"
exit 1
end
end
- # Creates a dictionary of names from memory
+ desc 'Creates a dictionary from memory - perform basic word search results operations'
task :from_memory do
LittleWeasel.configure do |config|
# TODO: Configure as needed here.
end
@@ -99,11 +100,11 @@
puts "LittleWeasel task word_results:from_memory not loaded: #{e.message}"
exit 1
end
end
- # Shows application of word filters and word preprocessors.
+ desc 'Creates a dictionary from memory - perform advanced word search results operations using word filters and preprocessors'
task :advanced do
LittleWeasel.configure do |config|
# TODO: Configure as needed here.
end
@@ -173,10 +174,11 @@
puts "LittleWeasel task word_results:advanced not loaded: #{e.message}"
exit 1
end
end
+ desc 'Creates a dictionary from memory - perform advanced word search results operations using word filters and preprocessors'
task :word_filters do
LittleWeasel.configure do |config|
# TODO: Configure as needed here.
end
dictionary_manager = LittleWeasel::DictionaryManager.new
@@ -215,10 +217,11 @@
#
# Tasks related to the #block_results API
namespace 'block_results' do
+ desc 'Perform basic #block_results API operations'
task :basic do
LittleWeasel.configure do |config|
# TODO: Configure as needed here.
end
@@ -251,45 +254,31 @@
end
end
end
namespace :bm do
+ desc 'Performs benchmarking on Hash lookups performance.'
task :hash do
STRING_LOCALE = { 'en-US' => 'en-us' }
- SYMBOL_LOCALE = { 'en-US' => :enUS }
+ SYMBOL_LOCALE = { enUS: 'en-US' }
- puts 'String variable vs. normal String.'
+ puts "Benchmark Hash lookups using different Hash key data types."
Benchmark.ips do |x|
- string_variable = 'string_variable'
+ string_variable = 'en-US'
+ x.report('hard-coded string') { STRING_LOCALE['en-US'] }
+ x.report('hard-coded frozen string') { STRING_LOCALE['en-US'.freeze] }
x.report('string variable') { STRING_LOCALE[string_variable] }
- x.report('normal') { STRING_LOCALE['en-US'] }
- end
-
- puts 'String#freeze vs. normal String.'
- Benchmark.ips do |x|
- x.report('freeze') { STRING_LOCALE['en-US'.freeze] }
- x.report('normal') { STRING_LOCALE['en-US'] }
- end
-
- puts 'String vs Symbol'
- Benchmark.ips do |x|
- x.report('string') { STRING_LOCALE['en-US'] }
x.report('symbol') { SYMBOL_LOCALE[:enUS] }
end
-
- puts 'String#freeze vs. Symbol'
- Benchmark.ips do |x|
- x.report('string') { STRING_LOCALE['en-US'.freeze] }
- x.report('symbol') { SYMBOL_LOCALE[:enUS] }
- end
rescue StandardError => e
task 'hash' do
puts "LittleWeasel task bm:hash not loaded: #{e.message}"
exit 1
end
end
+ desc 'Performs benchmarking on the DictionaryKey class.'
task :dictionary_key do
puts 'DictionaryKey test'
Benchmark.ips do |x|
x.report('DictionaryKey') do
DictionaryKey.key(language: :en, region: :us, tag: :tag)
@@ -301,6 +290,11 @@
exit 1
end
end
end
-task default: :spec
+
+desc 'Run LittleWeasel benchmark tests.'
+task benchmarking: %w[bm:hash bm:dictionary_key]
+
+RuboCop::RakeTask.new
+task default: %i[spec rubocop]