X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/c9ff9e8bb98709eabcfb7f1bc922d3f9649d7f31..52819d4ec98a27331c9cb6d1415f3a065ad81e60:/measure_energy_iot/client_tcp4.py?ds=sidebyside diff --git a/measure_energy_iot/client_tcp4.py b/measure_energy_iot/client_tcp4.py index f8b73f0..6485a5d 100644 --- a/measure_energy_iot/client_tcp4.py +++ b/measure_energy_iot/client_tcp4.py @@ -3,22 +3,93 @@ import threading import os import time import buffer +from PIL import Image +import sys +from io import BytesIO +from pathlib import Path +import numpy as np -HOST = 'bilbo' +HOST = "192.168.0.106" PORT = 2345 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) +nb_times=100 + +quality=int(sys.argv[1]) +print("quality ",quality) + + + + +im=Image.open("lena.jpg") +im.save("lena.bmp",quality=quality) +elapsed_time=0 +t = time.time() +for i in range(nb_times): + buf = BytesIO() + im.save(buf, "BMP", quality=quality) + +elapsed_time += time.time() - t + +print("compute bmp",elapsed_time/nb_times," / size of file ",Path('lena.bmp').stat().st_size) + + +""" +im=Image.open("lena.jpg") + +elapsed_time=0 +t = time.time() +for i in range(nb_times): + im.save("lena.bmp",quality=quality) + +elapsed_time += time.time() - t + +print("time bmp",elapsed_time/nb_times) +""" + + + +im=Image.open("lena.jpg") +elapsed_time=0 +im.save("lena2.jpg",quality=quality) +t = time.time() +for i in range(nb_times): + buf = BytesIO() + im.save(buf, "JPEG", quality=quality) + +elapsed_time += time.time() - t + +print("compute noscale jpg",elapsed_time/nb_times, " / size of file ",Path('lena2.jpg').stat().st_size) + + + +elapsed_time=0 +im2=im.resize((256, 256)) +im2.save("lena3.jpg",quality=quality) +t = time.time() +for i in range(nb_times): + im2=im.resize((256, 256)) + buf = BytesIO() + im2.save(buf, "JPEG", quality=quality) + +elapsed_time += time.time() - t +print("compute scale 4 jpg ",elapsed_time/nb_times, " / size of file ",Path('lena3.jpg').stat().st_size) + + + + + + with s: sbuf = buffer.Buffer(s) - elapsed_time=0 - t=time.time() - file_name="lena.jpg" - for i in range(10): - print(file_name) + elapsed_time=[] + file_name="lena.bmp" + for i in range(nb_times): + t=time.time() sbuf.put_utf8(file_name) file_size = os.path.getsize(file_name) @@ -26,15 +97,30 @@ with s: with open(file_name, 'rb') as f: sbuf.put_bytes(f.read()) - print('File Sent') - elapsed_time += time.time() - t - print("send lena ",elapsed_time) + elapsed_time.append(time.time() - t) - elapsed_time=0 - t=time.time() + print("send bmp mean",np.mean(elapsed_time), " std ",np.std(elapsed_time)) + + elapsed_time=[] file_name="lena2.jpg" - for i in range(10): - print(file_name) + for i in range(nb_times): + t=time.time() + sbuf.put_utf8(file_name) + + file_size = os.path.getsize(file_name) + sbuf.put_utf8(str(file_size)) + + with open(file_name, 'rb') as f: + sbuf.put_bytes(f.read()) + elapsed_time.append(time.time() - t) + + print("send noscale jpg mean",np.mean(elapsed_time), " std ",np.std(elapsed_time)) + + elapsed_time=[] + + file_name="lena3.jpg" + for i in range(nb_times): + t=time.time() sbuf.put_utf8(file_name) file_size = os.path.getsize(file_name) @@ -42,8 +128,7 @@ with s: with open(file_name, 'rb') as f: sbuf.put_bytes(f.read()) - print('File Sent') - elapsed_time += time.time() - t - print("send lena ",elapsed_time) + elapsed_time.append(time.time() - t) + print("send scale 4 jpg mean",np.mean(elapsed_time), " std ",np.std(elapsed_time))