Code: Select all
#!/bin/sh
for num in 1 2 3 4 5 6 7 8 9 0
do ./<script> &>/dev/null
done
Code: Select all
#!/bin/sh
dirs="/storage/photos"
find_images() {
find $@ -type f \
-iname "*.jp*g" \
-o -iname "*.png" \
-o -iname "*.svg" \
-o -iname "*.tif*"
}
find_images $dirs
Code: Select all
./test.sh 0.53s user 0.14s system 89% cpu 0.754 total
Code: Select all
#!/bin/sh
dirs="/storage/photos"
find_images() {
find $@ -type f \
| egrep ".jpg|.jpeg|.JPG|.png|.PNG|.tif|.tiff|.TIF|.svg" \
| while read line ; do echo "$line|$(basename "$line")" ; done
}
find_images $dirs
Code: Select all
./test.sh 13.12s user 17.36s system 25% cpu 1:57.86 total
Code: Select all
#!/bin/sh
dirs="/storage/photos"
find_images() {
find $@ -type f \
\( -iname "*.jp*g" \
-o -iname "*.png" \
-o -iname "*.svg" \
-o -iname "*.tif*" \) \
| while read line ; do echo "$line|$(basename "$line")" ; done
}
find_images $dirs
Code: Select all
./test.sh 13.83s user 16.92s system 26% cpu 1:54.15 total
Code: Select all
#!/bin/sh
dirs="/storage/photos"
find_images() {
find $@ -type f \
\( -iname "*.jp*g" \
-o -iname "*.png" \
-o -iname "*.svg" \
-o -iname "*.tif*" \) \
-exec echo -n '{}|' \; \
-exec basename '{}' \;
}
find_images $dirs
Code: Select all
./test.sh > /dev/null 4.64s user 19.18s system 15% cpu 2:34.87 total
Code: Select all
#!/usr/bin/env python
import os
import fnmatch
imagext = ['*.jpg', '*.JPG', '*.jpeg', '*.png', '*.PNG', '*.tif', '*.tiff', '*.svg']
dirs = ['/storage/photos']
def find_images(dir):
for root, dirnames, filenames in os.walk(dir):
for ext in imagext:
for filename in fnmatch.filter(filenames, ext):
fullpath = os.path.join(root, filename)
print (fullpath)
for dir in dirs:
find_images (dir)
Code: Select all
./test.sh 3.82s user 0.39s system 87% cpu 4.823 total
Code: Select all
#!/usr/bin/env python
import os
import fnmatch
imagext = ['*.jpg', '*.JPG', '*.jpeg', '*.png', '*.PNG', '*.tif', '*.tiff', '*.svg']
dirs = ['/storage/photos']
def find_images(dir):
for root, dirnames, filenames in os.walk(dir):
for ext in imagext:
for filename in fnmatch.filter(filenames, ext):
fullpath = os.path.join(root, filename)
print (fullpath, end='')
print ('|', end='')
print (filename)
for dir in dirs:
find_images (dir)
Code: Select all
./test.sh 4.32s user 0.39s system 87% cpu 5.389 total
Code: Select all
#!/usr/bin/env python
import os
import fnmatch
imagext = ['*.jpg', '*.JPG', '*.jpeg', '*.png', '*.PNG', '*.tif', '*.tiff', '*.svg']
dirs = ['/storage/photos']
def find_images(dir):
for root, dirnames, filenames in os.walk(dir):
for ext in imagext:
for filename in fnmatch.filter(filenames, ext):
fullpath = os.path.join(root, filename)
print (fullpath, end='')
print ('|', end='')
print (filename)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
for num in nums:
for dir in dirs:
find_images (dir)
Code: Select all
./find_images4.py &> /dev/null 3.44s user 0.33s system 87% cpu 4.304 total
I wouldn't go too far with conclusions, but a few things are pretty clear.
Even though the find utility handily beat my Python function, once anything is done with the data you invariably end up having to call upon other shell utilities, each of which take time to load slowing down the script. So even for a simple formatting exercise like this, Python was the clear speed winner. I'm beginning to see why some people love it so much. The shell is great for short scripts where execution time isn't a huge issue, but when dealing with large amounts of data (in this example we had over 50k lines after it looped 10x) the shell becomes painfully slow. I imagine a purpose written program in C would handily beat Python at the task, but that's not the point either. Do I even have a point...not sure.