+2  A: 

I suspect this is basically showing that the encryption isn't a significant part of the performance of this particular script.

However, getting the file system to load the contents of the directory the first time is significant. Once it's loaded, it's likely to be cached. That would explain why the first time you run both, whichever one is executed first will be slower. After that they're likely to be very similar, using the file system cache.

If you reboot (to make absolutely sure you're clearing the cache) and run it the other way round, I'd expect the encrypted version to take longer, simply because it'll be going to disk instead of the cache.

Jon Skeet
Reversing them equalized stuff but I tend to agree that caching and other complexities are hiding underneath. Lesson learned thank you for your time Jon.
ojblass
This is a good point. A way to remove fs effects would be to just use echos in the example.sh script.
Matthew Flaschen
+4  A: 

That's not a significant enough difference that I would conclude there's any effect. A better "profile" is:

#!/bin/bash

echo example.sh
/usr/bin/time sh -c 'for i in $(seq 1 1000); do ./example.sh; done'

echo example.sh.bin
/usr/bin/time sh -c 'for i in $(seq 1 1000); do ./example.sh.bin; done'

On my machine, I got:

example.sh
39.46user 33.22system 1:16.92elapsed 94%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+8547221minor)pagefaults 0swaps
example.sh.bin
42.33user 42.13system 1:33.98elapsed 89%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+9376313minor)pagefaults 0swaps

That is not enough to show definitively that the "encrypted" one is slower (though I obviously think it is), but it certainly shows that the encrypted doesn't consistently take less user time in a simple benchmark.

Also, there are some other serious issues with your code. Most obviously, this isn't close to sound encryption. As other people said, you're approaching the problem wrong. A encryption algorithm you come up with "in a matter of hours" is not a substitute for sound permissions.

Further, you need to use makefiles instead of proliferating unnecessary shell scripts. Learn rudimentary gcc options, like -o. Don't attempt to copy to /usr/bin/ unless the user runs an install target (in which case /usr/local/bin would still be better).

Matthew Flaschen
Thank you for your suggestions. I do know better but I get lazy during proof of concepts. The code less than first draft quality.
ojblass
I am looking at real encryption algorithms but this was too simple to pass up for a proof of concept.
ojblass
I had forgotten about $seq I was using let and a silly while variable a minute ago +1
ojblass
I find it a bit strange that time outputs the pagefault information and other stuff given this new profile scheme...
ojblass
/usr/bin/time is different from the shell built-in time. However, they both provide user time.
Matthew Flaschen
I learn more and more from you... thanks
ojblass
Mathew I wrapped it up in autotools and uploaded a copy to sourceforge. Thanks again. You can find the code at https://sourceforge.net/projects/shellcrypt/
ojblass