コード例 #1
0
def test_tiff(path):
    fd = open(path, 'rb')
    f_tiff = fd.read()
    fd.close()

    tiff = TIFF()
    tiff.from_bytes(f_tiff)
    tiff.reautomate()
    assert (tiff.to_bytes() == f_tiff)
コード例 #2
0
def test_perf_media(bmp_path, png_path, jpg_path, tiff_path, gif_path,
                    mp4_path, mp3_path):

    fd = open(bmp_path, 'rb')
    f_bmp = fd.read()
    fd.close()

    def test_bmp(f_bmp=f_bmp, fmt=BMP):
        bmp = BMP()
        bmp.from_bytes(f_bmp)

    print('[+] instantiating and parsing BMP in LBUF mode')
    BMP._GEN = BMP._GEN_LBUF
    Ta = timeit(test_bmp, number=150)
    print('test_bmp: {0:.4f}'.format(Ta))

    bmp = BMP()
    bmp.from_bytes(f_bmp)
    bmp.reautomate()
    print('[+] regenerating BMP in LBUF mode')
    Tb = timeit(bmp.to_bytes, number=200)
    print('bmp.to_bytes: {0:.4f}'.format(Tb))

    print('[+] instantiating and parsing BMP in LPIX mode')
    BMP._GEN = BMP._GEN_LPIX
    Tc = timeit(test_bmp, number=3)
    print('test_bmp: {0:.4f}'.format(Tc))

    bmp = BMP()
    bmp.from_bytes(f_bmp)
    bmp.reautomate()
    print('[+] regenerating BMP in LPIX mode')
    Td = timeit(bmp.to_bytes, number=2)
    print('bmp.to_bytes: {0:.4f}'.format(Td))

    fd = open(png_path, 'rb')
    f_png = fd.read()
    fd.close()

    def test_png(f_png=f_png):
        png = PNG()
        png.from_bytes(f_png)

    print('[+] instantiating and parsing PNG')
    Te = timeit(test_png, number=120)
    print('test_png: {0:.4f}'.format(Te))

    png = PNG()
    png.from_bytes(f_png)
    png.reautomate()
    print('[+] regenerating PNG')
    Tf = timeit(png.to_bytes, number=350)
    print('png.to_bytes: {0:.4f}'.format(Tf))

    fd = open(jpg_path, 'rb')
    f_jpg = fd.read()
    fd.close()

    def test_jpg(f_jpg=f_jpg):
        jpeg = JPEG()
        jpeg.from_bytes(f_jpg)

    print('[+] instantiating and parsing JPEG')
    Tg = timeit(test_jpg, number=30)
    print('test_png: {0:.4f}'.format(Tg))

    jpeg = JPEG()
    jpeg.from_bytes(f_jpg)
    jpeg.reautomate()
    print('[+] regenerating JPEG')
    Th = timeit(jpeg.to_bytes, number=60)
    print('jpeg.to_bytes: {0:.4f}'.format(Th))

    fd = open(tiff_path, 'rb')
    f_tiff = fd.read()
    fd.close()

    def test_tiff(f_tiff=f_tiff):
        tiff = TIFF()
        tiff.from_bytes(f_tiff)

    print('[+] instantiating and parsing TIFF')
    Ti = timeit(test_tiff, number=60)
    print('test_tiff: {0:.4f}'.format(Ti))

    tiff = TIFF()
    tiff.from_bytes(f_tiff)
    tiff.reautomate()
    print('[+] regenerating TIFF')
    Tj = timeit(tiff.to_bytes, number=240)
    print('tiff.to_bytes: {0:.4f}'.format(Tj))

    fd = open(gif_path, 'rb')
    f_gif = fd.read()
    fd.close()

    def test_gif(f_gif=f_gif):
        gif = GIF()
        gif.from_bytes(f_gif)

    print('[+] instantiating and parsing GIF')
    Tk = timeit(test_gif, number=8)
    print('test_gif: {0:.4f}'.format(Tk))

    gif = GIF()
    gif.from_bytes(f_gif)
    gif.reautomate()
    print('[+] regenerating GIF')
    Tl = timeit(gif.to_bytes, number=12)
    print('gif.to_bytes: {0:.4f}'.format(Tl))

    fd = open(mp4_path, 'rb')
    f_mp4 = fd.read()
    fd.close()

    def test_mp4(f_mp4=f_mp4):
        mp4 = MPEG4()
        mp4.from_bytes(f_mp4)

    print('[+] instantiating and parsing MPEG4')
    Tm = timeit(test_mp4, number=12)
    print('test_mp4: {0:.4f}'.format(Tm))

    mp4 = MPEG4()
    mp4.from_bytes(f_mp4)
    mp4.reautomate()
    print('[+] regenerating MPEG4')
    Tn = timeit(mp4.to_bytes, number=50)
    print('mp4.to_bytes: {0:.4f}'.format(Tn))

    fd = open(mp3_path, 'rb')
    f_mp3 = fd.read()
    fd.close()

    def test_mp3(f_mp3=f_mp3):
        mp3 = MP3()
        mp3.from_bytes(f_mp3)

    print('[+] instantiating and parsing MP3')
    To = timeit(test_mp3, number=60)
    print('test_mp3: {0:.4f}'.format(To))

    mp3 = MP3()
    mp3.from_bytes(f_mp3)
    mp3.reautomate()
    print('[+] regenerating MP3')
    Tp = timeit(mp3.to_bytes, number=180)
    print('mp3.to_bytes: {0:.4f}'.format(Tp))

    print('[+] fmt_media total time: {0:.4f}'\
          .format(Ta+Tb+Tc+Td+Te+Tf+Ti+Tj+Tk+Tl+Tm+Tn+To+Tp))