9 from pathlib import Path
12 HOST = "192.168.0.106"
15 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
16 s.connect((HOST, PORT))
20 quality=int(sys.argv[1])
21 print("quality ",quality)
26 im=Image.open("lena.jpg")
27 im.save("lena.bmp",quality=quality)
30 for i in range(nb_times):
32 im.save(buf, "BMP", quality=quality)
34 elapsed_time += time.time() - t
36 print("compute bmp",elapsed_time/nb_times," / size of file ",Path('lena.bmp').stat().st_size)
40 im=Image.open("lena.jpg")
44 for i in range(nb_times):
45 im.save("lena.bmp",quality=quality)
47 elapsed_time += time.time() - t
49 print("time bmp",elapsed_time/nb_times)
54 im=Image.open("lena.jpg")
56 im.save("lena2.jpg",quality=quality)
58 for i in range(nb_times):
60 im.save(buf, "JPEG", quality=quality)
62 elapsed_time += time.time() - t
64 print("compute noscale jpg",elapsed_time/nb_times, " / size of file ",Path('lena2.jpg').stat().st_size)
69 im2=im.resize((256, 256))
70 im2.save("lena3.jpg",quality=quality)
72 for i in range(nb_times):
73 im2=im.resize((256, 256))
75 im2.save(buf, "JPEG", quality=quality)
77 elapsed_time += time.time() - t
78 print("compute scale 4 jpg ",elapsed_time/nb_times, " / size of file ",Path('lena3.jpg').stat().st_size)
86 sbuf = buffer.Buffer(s)
91 for i in range(nb_times):
93 sbuf.put_utf8(file_name)
95 file_size = os.path.getsize(file_name)
96 sbuf.put_utf8(str(file_size))
98 with open(file_name, 'rb') as f:
99 sbuf.put_bytes(f.read())
100 elapsed_time.append(time.time() - t)
102 print("send bmp mean",np.mean(elapsed_time), " std ",np.std(elapsed_time))
105 file_name="lena2.jpg"
106 for i in range(nb_times):
108 sbuf.put_utf8(file_name)
110 file_size = os.path.getsize(file_name)
111 sbuf.put_utf8(str(file_size))
113 with open(file_name, 'rb') as f:
114 sbuf.put_bytes(f.read())
115 elapsed_time.append(time.time() - t)
117 print("send noscale jpg mean",np.mean(elapsed_time), " std ",np.std(elapsed_time))
121 file_name="lena3.jpg"
122 for i in range(nb_times):
124 sbuf.put_utf8(file_name)
126 file_size = os.path.getsize(file_name)
127 sbuf.put_utf8(str(file_size))
129 with open(file_name, 'rb') as f:
130 sbuf.put_bytes(f.read())
131 elapsed_time.append(time.time() - t)
133 print("send scale 4 jpg mean",np.mean(elapsed_time), " std ",np.std(elapsed_time))