Last active
December 25, 2015 02:09
-
-
Save Locke23rus/6901048 to your computer and use it in GitHub Desktop.
Words stats
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
| user system total real | |
| via_uniq_and_count 6.340000 0.000000 6.340000 ( 6.356359) | |
| via_each 1.250000 0.000000 1.250000 ( 1.259036) |
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
| # -*- encoding : utf-8 -*- | |
| require 'benchmark' | |
| iterations = 100 | |
| pretexts = ['и','в', 'без', 'до', 'из', 'к', 'на', 'по', 'о', 'от', 'перед', 'при', 'через', 'с', 'у', 'за', 'над', 'об', 'под', 'про', 'для','вблизи', 'вглубь', 'вдоль', 'возле', 'около', 'вокруг', 'впереди', 'после' , 'др','в', 'с', 'к', 'у', 'над', 'на', 'перед', 'при','из-под', 'из-за', 'по-над' ] | |
| @stems = pretexts * 1_000 | |
| def via_uniq_and_count | |
| wstat = {} | |
| @stems.uniq.each do |uniqstem| | |
| wstat[uniqstem] = @stems.count(uniqstem) | |
| end | |
| wstat = Hash[wstat.sort_by{|_, v| v}.reverse] | |
| end | |
| def via_each | |
| wstat = Hash.new(0) | |
| @stems.each { |stem| wstat[stem] += 1 } | |
| wstat = Hash[wstat.sort_by{|_, v| v}.reverse] | |
| end | |
| #puts via_uniq_and_count | |
| #puts via_each | |
| Benchmark.bm(20) do |bm| | |
| bm.report('via_uniq_and_count') do | |
| iterations.times { via_uniq_and_count } | |
| end | |
| bm.report('via_each') do | |
| iterations.times { via_each } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment