File: bench.py

package info (click to toggle)
python-imagesize 0.7.1-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 572 kB
  • sloc: python: 130; makefile: 5
file content (34 lines) | stat: -rw-r--r-- 822 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import timeit
import os, sys
sys.path.insert(0, os.path.dirname(__file__))
import imagesize

imagepath = os.path.join(os.path.dirname(__file__), "test", "images", "test.png")

try:
    from PIL import Image
except ImportError:
    try:
        import Image
    except ImportError:
        Image = None

def get_by_pil(filepath):
    img = Image.open(filepath)
    (width, height) = img.size
    return width, height

def bench_purepython():
    imagesize.get(imagepath)

def bench_pil():
    get_by_pil(imagepath)

def bench():
    print("pure python png")
    print(timeit.timeit('bench_purepython()', number=100000, setup="from __main__ import bench_purepython"))
    print("pil png")
    print(timeit.timeit('bench_pil()', number=100000, setup="from __main__ import bench_pil"))

if __name__ == "__main__":
    bench()