Skip to content

Instantly share code, notes, and snippets.

@snk4tr
Created August 10, 2018 06:59
Show Gist options
  • Select an option

  • Save snk4tr/c499f1a0052deb6e6eb7990196067e4b to your computer and use it in GitHub Desktop.

Select an option

Save snk4tr/c499f1a0052deb6e6eb7990196067e4b to your computer and use it in GitHub Desktop.
import functools
import cv2
from skimage import io
from PIL import Image
def time_logger(func):
@functools.wraps(func)
def wrapped(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
finish = time.time()
stage_time = time.strftime('%d.%m.%Y - %H:%M ') + "*** METHOD {} TOOK {} SECONDS! ***\n"\
.format(func.__qualname__, (finish - start))
print(stage_time)
return result
return wrapped
############ OpenCV ############
@time_logger
def opencv():
imgs = []
for fname in x_tr_fnames:
imgs.append(cv2.cvtColor(cv2.imread(fname), cv2.COLOR_BGR2RGB))
############ SciMage ############
@time_logger
def scimage():
imgs = []
for fname in x_tr_fnames:
imgs.append(io.imread(fname))
############ Pillow ############
@time_logger
def pillow():
imgs = []
for fname in x_tr_fnames:
imgs.append(np.array(Image.open(fname)))
opencv()
scimage()
pillow()
@snk4tr
Copy link
Author

snk4tr commented Aug 10, 2018

1000 images results:

10.08.2018 - 06:38 *** METHOD opencv TOOK 0.28897571563720703 SECONDS! ***

10.08.2018 - 06:38 *** METHOD scimage TOOK 0.8074595928192139 SECONDS! ***

10.08.2018 - 06:38 *** METHOD pillow TOOK 0.7951657772064209 SECONDS! ***

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment