#!python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2022/07/07 08:16:02 +0900> """ Pillow .getpixel(), .load(), .getdata() benchmark Windows10 x64 21H2 + Python 3.9.13 64bit + Pillow 9.1.1 """ from PIL import Image from benchmarker import Benchmarker infile = "teen-girl-4467541_4288x2848.jpg" def main(): im = Image.open(infile) width, height = im.size print("%d x %d" % (width, height)) with Benchmarker(100) as bench: @bench(".getdata()") def _(bm): im = Image.open(infile) dt = im.getdata() for y in range(height): idx = width * y for x in range(width): _ = dt[idx + x] @bench(".load()") def _(bm): im = Image.open(infile) src = im.load() for y in range(height): for x in range(width): _ = src[x, y] @bench(".getpixel()") def _(bm): im = Image.open(infile) for y in range(height): for x in range(width): _ = im.getpixel((x, y)) if __name__ == '__main__': main()