Skip to content

Instantly share code, notes, and snippets.

@yujikosuga
Created January 25, 2016 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yujikosuga/3ec7e8e310391179d0f1 to your computer and use it in GitHub Desktop.
Save yujikosuga/3ec7e8e310391179d0f1 to your computer and use it in GitHub Desktop.
Computation Time of ^(a+)+$ by Programming Language
# Perl Computation Time of ^(a+)+$
$ time perl -e 'print (("a"x100 . "b") =~ /^(a+)+$/)'
real 0m0.010s
user 0m0.003s
sys 0m0.004s
$ time perl -e 'print (("a"x1000 . "b") =~ /^(a+)+$/)'
real 0m0.011s
user 0m0.004s
sys 0m0.005s
$ time perl -e 'print (("a"x10000 . "b") =~ /^(a+)+$/)'
real 0m0.010s
user 0m0.005s
sys 0m0.004s
$ time perl -e 'print (("a"x100000 . "b") =~ /^(a+)+$/)'
real 0m0.027s
user 0m0.021s
sys 0m0.004s
$ time perl -e 'print (("a"x1000000 . "b") =~ /^(a+)+$/)'
real 0m0.188s
user 0m0.179s
sys 0m0.007s
$ time perl -e 'print (("a"x10000000 . "b") =~ /^(a+)+$/)'
real 0m1.725s
user 0m1.705s
sys 0m0.016s
$ time perl -e 'print (("a"x100000000 . "b") =~ /^(a+)+$/)'
real 0m17.504s
user 0m17.209s
sys 0m0.181s
# Python Computation Time of ^(a+)+$
$ time python -c 'import re;re.match(r"^(a+)+$","a"*1+"b")'
real 0m0.024s
user 0m0.012s
sys 0m0.010s
$ time python -c 'import re;re.match(r"^(a+)+$","a"*10+"b")'
real 0m0.023s
user 0m0.012s
sys 0m0.009s
$ time python -c 'import re;re.match(r"^(a+)+$","a"*100+"b")'
... Very long time. ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment