From 13e5945d82c726bfd1eaabad2cb261fdfc6a63ab Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Mon, 30 Nov 2015 20:40:23 +0900 Subject: [PATCH] Create `rake bench` task --- Rakefile | 11 +++++++++++ bin/bench | 2 +- bin/clone | 6 +++--- wercker.yml | 18 +++++++++--------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Rakefile b/Rakefile index 138c3fe3..92127df5 100644 --- a/Rakefile +++ b/Rakefile @@ -75,5 +75,16 @@ Rake::ExtensionTask.new(:hamlit) do |ext| ext.lib_dir = 'lib/hamlit' end +desc 'bench task for CI' +task bench: :compile do + if ENV['SLIM_BENCH'] == '1' + cmd = %w[bundle exec ruby benchmark/slim/run-benchmarks.rb] + else + cmd = ['bin/bench', 'bench', ('-c' if ENV['COMPILE'] == '1'), *ENV['TEMPLATE'].split(',')].compact + end + system('bin/clone') + exit system(*cmd) +end + task default: %w[compile hamlit:test] task test: %w[compile test:all] diff --git a/bin/bench b/bin/bench index b7d74433..47cc9f91 100755 --- a/bin/bench +++ b/bin/bench @@ -15,7 +15,7 @@ class Bench < Thor option :compile, type: :boolean, aliases: ['-c'] option :show_code, type: :boolean, aliases: ['-s'] def bench(*files) - files.each { |file| render(file) } + files.each { |file| render(file) unless options[:compile] } files.each { |file| compile(file) if options[:compile] } files.each { |file| code(file) if options[:show_code] } end diff --git a/bin/clone b/bin/clone index 2c7a4f17..a345404a 100755 --- a/bin/clone +++ b/bin/clone @@ -1,14 +1,14 @@ #!/bin/bash if [ -e hamlit1 ]; then - echo 'skipped' + echo 'With hamlit1' exit 0 fi git clone --depth=1 -b v1.7.2 https://github.com/k0kubun/hamlit hamlit1 cd hamlit1 -git grep --name-only Hamlit | xargs sed -i "" -e "s/Hamlit/Hamlit1/g" -git grep --name-only hamlit | xargs sed -i "" -e "s/hamlit/hamlit1/g" +git grep --name-only Hamlit | xargs sed -i "" -e "s/Hamlit/Hamlit1/g" 2> /dev/null +git grep --name-only hamlit | xargs sed -i "" -e "s/hamlit/hamlit1/g" 2> /dev/null git mv hamlit.gemspec hamlit1.gemspec git mv lib/hamlit.rb lib/hamlit1.rb git mv lib/hamlit lib/hamlit1 diff --git a/wercker.yml b/wercker.yml index 7ceb6154..80e8e494 100644 --- a/wercker.yml +++ b/wercker.yml @@ -9,24 +9,24 @@ build: - bundle-install - - script: - name: clone hamlit1 - code: bin/clone - script: name: test all code: bundle exec rake test - - script: - name: Hamlit::AttributeBuilder.build_data micro benchmark - code: benchmark/ext/build_data.rb - script: name: "[benchmark] static attributes" - code: bin/bench bench -t benchmark/boolean_attribute.haml benchmark/class_attribute.haml benchmark/id_attribute.haml benchmark/data_attribute.haml benchmark/common_attribute.haml + code: TEMPLATE=benchmark/boolean_attribute.haml,benchmark/class_attribute.haml,benchmark/id_attribute.haml,benchmark/data_attribute.haml,benchmark/common_attribute.haml bundle exec rake bench - script: name: "[benchmark] dynamic attributes" - code: bin/bench bench -t benchmark/dynamic_attributes/boolean_attribute.haml benchmark/dynamic_attributes/class_attribute.haml benchmark/dynamic_attributes/id_attribute.haml benchmark/dynamic_attributes/data_attribute.haml benchmark/dynamic_attributes/common_attribute.haml + code: TEMPLATE=benchmark/dynamic_attributes/boolean_attribute.haml,benchmark/dynamic_attributes/class_attribute.haml,benchmark/dynamic_attributes/id_attribute.haml,benchmark/dynamic_attributes/data_attribute.haml,benchmark/dynamic_attributes/common_attribute.haml bundle exec rake bench - script: name: "[benchmark] attribute_builder bench by faml" - code: bin/bench bench -t benchmark/etc/attribute_builder.haml + code: TEMPLATE=benchmark/etc/attribute_builder.haml bundle exec rake bench + - script: + name: "[benchmark] benchmark by slim" + code: SLIM_BENCH=1 bundle exec rake bench + - script: + name: "[benchmark] compilation of haml's standard.haml" + code: TEMPLATE=test/haml/templates/standard.haml COMPILE=1 bundle exec rake bench - rvm-use: version: 2.1.7