Last active
February 16, 2018 12:10
-
-
Save ianmiell/74b8fe23758f001e4f862b3e2d02e3d0 to your computer and use it in GitHub Desktop.
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
imiell@basquiat $ cat a.sh | |
#!/bin/bash | |
for i in {1..100000} | |
do | |
VAR='HEADERMy voice is my passwordFOOTER' | |
PASS=${VAR#HEADER} | |
PASS=${PASS%FOOTER} | |
done | |
imiell@basquiat $ cat a.py | |
for i in range(100000): | |
var = 'HEADERMy voice is my passwordFOOTER' | |
password = var.lstrip('HEADER') | |
password = password.rstrip('FOOTER') | |
imiell@basquiat $ time ./a.sh | |
real 0m2.442s | |
user 0m2.395s | |
sys 0m0.026s | |
imiell@basquiat $ time python a.py | |
real 0m0.104s | |
user 0m0.085s | |
sys 0m0.010s | |
imiell@basquiat $ cat a.sh | |
#!/bin/bash | |
for i in {1..1000} | |
do | |
VAR='HEADERMy voice is my passwordFOOTER' | |
PASS=${VAR#HEADER} | |
PASS=${PASS%FOOTER} | |
done | |
imiell@basquiat $ cat a.py | |
for i in range(1000): | |
var = 'HEADERMy voice is my passwordFOOTER' | |
password = var.lstrip('HEADER') | |
password = password.rstrip('FOOTER') | |
imiell@basquiat $ time ./a.sh | |
real 0m0.035s | |
user 0m0.034s | |
sys 0m0.001s | |
imiell@basquiat $ time python a.py | |
real 0m0.029s | |
user 0m0.016s | |
sys 0m0.013s |
Fair point - out of context this makes less sense. I was looking for a speed comparison to prove bash is slower. But it wasn't.
Except that the startup time of python makes a difference here - have updated the gist to reflect the fact that bash is slower after all.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that
(l|r|)strip()
doesn't strip the verbatim strings you pass in, but any number of the characters passed in! That is,.strip('HEADER')
is equivalent to.strip('ADEHR')
, for instance, and if the password we want to get at happened to start with any of those characters (or ended with any number of E, F, O, T, or R), those would have gotten stripped as well and we'd ended up with the wrong password.A more equivalent version would be
(or you could use the
re
module).