Last active
December 10, 2015 19:38
-
-
Save yamagata-kozo/4482177 to your computer and use it in GitHub Desktop.
rubyの文字列検索
This file contains 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 | |
Regexp: 13.720000 0.540000 14.260000 ( 15.841062) | |
index: 3.750000 0.140000 3.890000 ( 4.202292) | |
include?: 3.510000 0.130000 3.640000 ( 3.867318) |
This file contains 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
# coding: utf-8 | |
require 'benchmark' | |
n = 10000 | |
tweet = '沢山はセロの拍手舌団がゃくしゃしていましたがいつまでもつづけてから見る光輝ました。いやこんこん粗末ましましとかいう糸ましん。くたくたたでしのだっはましではトルコ風呂ゴーシュのそれどころたちのときにもばたばた上手たまして、それほど床に許しられるのでない。なっすぎみんなは虎にないですて今日の間' | |
ng_words = '部落,特殊部落,人非人,身元調査,過去帳,興信所,特殊学級,めくら,つんぼ,あきめくら,おし,どもり,びっこ,ちんば,いざり,かたわ,がちゃ目,ロンパリ,業病,かさっかき,ライ病,植物人間,白痴,こけ,のうまくえん,きちがい,しらっこ,せむし,みつくち,台湾ハゲ,馬鹿でもチョンでも,つんぼ桟敷,片手落ち,てんぼう,バカチョンカメラ,自閉症児,精神薄弱児,心身障害者,知恵遅れ,犬殺し,おわい屋,汲み取り屋,クズ屋,バタ屋,ゴミ屋,おんぼう,屠殺,屠殺人,屠殺場,番太,おまわり,運ちゃん,沖仲仕,かつぎ屋,給仕,漁夫,芸人,周旋屋,下女,下男,女中,百姓,どん百姓,土方,土工,人足,人夫,雑役夫,三助,女給,女工,職工,線路工夫,日雇い,ニコヨン,小僧,丁稚,土建屋,タケノコ医者,ヤブ医者,町医者,床屋,代書屋,共稼ぎ,馬丁,馬喰,郵便屋,潜水夫,くろんぼ,ニガー,ニグロ,アメ公,イタ公,ロスケ,ジャップ,チャンコロ,支那人,ジュー,ポコペン,毛唐,紅毛人,鮮人,半島人,南鮮,北鮮,中共,土人,後進国,低開発国,ダッチマン,あいのこ,支那チク,支那料理,支那そば,日本のチベット,三韓征伐,朝鮮征伐,トルコ風呂,トルコ嬢,老婆,裏日本,表日本,出戻り,オールドミス,スケ,ナオン,イモ,あらめん,まえつき,ほんぼし,シマ,ペイ患,おとしまえ,やばい,ずらかる,ブタ箱,サツ,デカ,ガサ,強姦,あて馬,ネコババ,イカサマ,股にかける,くわえこむ,インチキ,アオカン,すけこまし,土左衛門,ゲンナマ,チャリンコ,ノビ,ヒモ,かわかぶり,ゲーセン,せんずり,ヤー様,地まわり,やさぐれ,淫売,姦通,パクる,南部のシャケの鼻まがり,越後の米つき,富山の三助,上方のぜい六,伊勢こじき,いちゃもんをつける,うんこ,女子供,婿をとる,嫁にやる,娘をかたづける,しりぬぐい,足切り,首切り,落ちこぼれ,溺れ死ぬ' | |
Benchmark.bm do |x| | |
x.report('Regexp:') do | |
n.times do | |
regexp = Regexp.new(ng_words.gsub(/,/, '|')) | |
tweet =~ regexp | |
end | |
end | |
x.report('index:') do | |
n.times do | |
result = false | |
ng_words.split(',').each do |word| | |
result = tweet.index(word) | |
break if result | |
end | |
result | |
end | |
end | |
x.report('include?:') do | |
n.times do | |
result = false | |
ng_words.split(',').each do |word| | |
result = tweet.include?(word) | |
break if result | |
end | |
result | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment