ãã¡ãã§ãã
ã¨ã«ããã«ã¸ã¥ã¢ã«ã«ãç°¡åã§ãããã®ã§æ£è¦è¡¨ç¾ã使ãããå ´é¢ã«ãããããã¨æãã
ç°¡åãªãã³ããåã£ãã
ä»ã®ä¸»è¦ãª3ã¤ã®mgemï¼mruby-onig-regexp/mruby-regexp-pre/mruby-pure-regexpï¼ã¨æ¯è¼ãã¦ãçµæçã« mruby-posix-regexp ãä¸çªãã«ãæéããã¤ããªãµã¤ãºã¨ãã«å°ãããªãã¨ããçµæã«ãªã£ãã
ãã³ãã®å 容
ã¾ãã mruby 3.0.0 ã«ããã¦ã以ä¸ãããªæå°éã® build_config.rb ãç¨ããã
MRuby::Build.new do |conf| conf.toolchain conf.gem mgem: 'mruby-onig-regexp' #conf.gem mgem: 'mruby-regexp-pcre' #conf.gem mgem: 'mruby-pure-regexp' #conf.gem mgem: 'mruby-posix-regexp' conf.gem core: 'mruby-bin-mruby' end
æ¯è¼å 容ã¨ãã¦ã
rake deep_clean
å¾ã«ä¸ãããã«ãããéã®ãã«ãæè¦æé- çæããã mruby ãã¤ããªã®ãµã¤ãº
ãæ¯è¼ãããã³ãã³ãã®ä¾:
$ rake deep_clean $ time env MRUBY_CONFIG=onig_re rake .... real 0m44.950s user 0m38.223s sys 0m2.880s $ ls -l bin/mruby -rwxrwxr-x 1 vagrant vagrant 5532312 Sep 22 16:03 bin/mruby
ã¾ãããã©ã¼ãã³ã¹ã®ãã³ãã¨ãã¦ã以ä¸ã®ã¹ã¯ãªãããèµ°ãããã
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." text = ([text] * 100).join ' ' r = 0 100.times do r = text.scan(/\w+/).size end # mruby-io ãå«ã¾ãªãã®ã§ä¾å¤ã§ä»¶æ°ãåºåãã¦ãã raise "size of words: #{r}"
ãªããæ£å¸¸ã«çµäºããå ´å 6900
ãåºåããã
$ time ./bin/mruby ../scan.rb trace (most recent call last): ../scan.rb:8: size of words: 6900 (RuntimeError) real 0m1.084s user 0m1.071s sys 0m0.013s
æ¤è¨¼ç°å¢ã¯ 15 ã³ã¢ã8GBã®ã¡ã¢ãªãå²ãå½ã¦ãVirtualBoxä¸ã®VMï¼æ¯è¦ã®Macã¯Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHzã16ã³ã¢ï¼ã¨ããããã ãmrubyã¯ä¸¦è¡ãã«ãã並è¡å®è¡ãããªãã®ã§ã³ã¢æ°ã®å½±é¿ã¯å°ããã®ã§ã¯ãªããã¨æãã
æ¤è¨¼çµæ
- | onig | pcre | pure | posix |
---|---|---|---|---|
ãã«ãæè¦æé(s) | 44.95 | 33.745 | 29.37 | 27.699 |
ãã¤ããªãµã¤ãº(bytes) | 5532312 | 4477416 | 4137960 | 3956200 |
ãã³ãæé(s) | 1.084 | 5.395 | -(*1) | 4.307 |
(*1) å®è¡ä¸ã«OOMã«ããKillããã¦ãã¾ã£ãããè¨æ¸¬ã§ãããå®è¡çµæã®åºåãåèã¾ã§ã«:
$ time ./bin/mruby ../scan.rb Killed real 0m5.271s user 0m2.508s sys 0m2.751s
ã°ã©ã
èå¯
- ä¾åã©ã¤ãã©ãªãå°ããï¼ããæ£ç¢ºã«ã¯ãCæ¡å¼µã¨ãã¦å¤é¨ã©ã¤ãã©ãªããã«ãããªãããã«ãããã£ãï¼ãã¤ã³ã¹ãã¼ã«ãæ°è»½ã«ã¨èãã¦ä½ã£ããã®ã ããçµæçã«Cæ¡å¼µé¨åããªã mruby-pure-regexp ããããã«ãæéã»ãã¤ããªãµã¤ãºã¨ãè¥å¹²å°ãããªã£ãã
- å®è¡é度ã ãã§è¦ãã¨Onigmoãã¨ãã§ããªãé«éãªã®ã§ãå¼ãç¶ãæ®éã®mrubyã¢ããªã±ã¼ã·ã§ã³ã§ã¯æã使ãããé¸æè¢ã«ãªãã®ã¯ééããªãããã
- posix regexpãªã®ã§ã ããã¤ãã®Rubyã®æ£è¦è¡¨ç¾ãã¯ãã¨ãã¨ã使ããªãã¨èããæ¹ããã ã¨æããä¾ãã°
\A
\z
\d
ãªã©ã¯ä½¿ããªããããã§æ§ããªã人ã使ããã¨ã«ãªãã
å¾®å¦ã«ä½¿ãã©ããããªãããã ããæ¬å½ã«ã¡ãã³ã£ã¨ä½¿ãããã ããªã®ã«ãã¤ããªãµã¤ãºããã«ãæéãå¢å¤§ããã®ã¯... ã¨ããããããªå ´é¢ã§ã¯ããã®ããã
ã¡ãªã¿ã«ã mruby-optparse ãæ£è¦è¡¨ç¾ã«ä¾åããã¨ãã話ããããã¡ãã£ã¨ãããã¼ã«ã§Onigmoããã³ãã«ãããã¡ã§ãã£ãããGNUæ£è¦è¡¨ç¾ã§ããç¨åº¦åãããã«ãããã©ã¼ã¯ã以ä¸ã«ä½ã£ã¦ããï¼ãã£ã¨ãã¹ãã±ã¼ã¹å¢ãããªãã¨ä¸å®ã ãã©...ï¼ã
ã¾ã¨ã
ããããªæ£è¦è¡¨ç¾ã¯ã©ã¹å®è£ mgem ãä½ã£ãã
ãã¹ãã±ã¼ã¹ã足ãã¦ãããããã人ãæè¿ãã¦ãã¾ãã