]> AND Private Git Repository - Cipher_code.git/blob - measure_energy_iot/client_tcp4.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
new
[Cipher_code.git] / measure_energy_iot / client_tcp4.py
1 import socket
2 import threading
3 import os
4 import time
5 import buffer
6 from PIL import Image
7 import sys
8 from io import BytesIO
9 from pathlib import Path
10
11
12 HOST = "192.168.0.106"
13 PORT = 2345
14
15 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
16 s.connect((HOST, PORT))
17
18 nb_times=10
19
20 quality=int(sys.argv[1])
21 print("quality ",quality)
22
23
24
25
26 im=Image.open("lena.jpg")
27 im.save("lena.bmp",quality=quality)
28 elapsed_time=0
29 t = time.time()
30 for i in range(nb_times):
31     buf = BytesIO()
32     im.save(buf, "BMP", quality=quality)
33
34 elapsed_time += time.time() - t
35
36 print("compute bmp",elapsed_time/nb_times," / size of file ",Path('lena.bmp').stat().st_size)
37
38
39 """
40 im=Image.open("lena.jpg")
41
42 elapsed_time=0
43 t = time.time()
44 for i in range(nb_times):
45     im.save("lena.bmp",quality=quality)
46
47 elapsed_time += time.time() - t
48
49 print("time bmp",elapsed_time/nb_times)
50 """
51
52
53
54 im=Image.open("lena.jpg")
55 elapsed_time=0
56 im.save("lena2.jpg",quality=quality)
57 t = time.time()
58 for i in range(nb_times):
59     buf = BytesIO()
60     im.save(buf, "JPEG", quality=quality)
61     
62 elapsed_time += time.time() - t
63
64 print("compute noscale jpg",elapsed_time/nb_times, " / size of file ",Path('lena2.jpg').stat().st_size)
65
66
67
68 elapsed_time=0
69 im2=im.resize((256, 256))
70 im2.save("lena3.jpg",quality=quality)
71 t = time.time()
72 for i in range(nb_times):
73     im2=im.resize((256, 256))
74     buf = BytesIO()
75     im2.save(buf, "JPEG", quality=quality)
76     
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)
79
80
81
82
83
84
85 with s:
86     sbuf = buffer.Buffer(s)
87
88
89     elapsed_time=0
90     t=time.time()
91     file_name="lena.bmp"
92     for i in range(nb_times):
93 #        print(file_name)
94         sbuf.put_utf8(file_name)
95
96         file_size = os.path.getsize(file_name)
97         sbuf.put_utf8(str(file_size))
98
99         with open(file_name, 'rb') as f:
100             sbuf.put_bytes(f.read())
101 #        print('File Sent')
102     elapsed_time += time.time() - t    
103     print("send bmp ",elapsed_time/nb_times)
104
105     elapsed_time=0
106     t=time.time()
107     file_name="lena2.jpg"
108     for i in range(nb_times):
109  #       print(file_name)
110         sbuf.put_utf8(file_name)
111
112         file_size = os.path.getsize(file_name)
113         sbuf.put_utf8(str(file_size))
114
115         with open(file_name, 'rb') as f:
116             sbuf.put_bytes(f.read())
117  #       print('File Sent')
118     elapsed_time += time.time() - t    
119     print("send noscale jpg ",elapsed_time/nb_times)
120
121     elapsed_time=0
122     t=time.time()
123     file_name="lena3.jpg"
124     for i in range(nb_times):
125  #       print(file_name)
126         sbuf.put_utf8(file_name)
127
128         file_size = os.path.getsize(file_name)
129         sbuf.put_utf8(str(file_size))
130
131         with open(file_name, 'rb') as f:
132             sbuf.put_bytes(f.read())
133  #       print('File Sent')
134     elapsed_time += time.time() - t    
135     print("send scale 4 jpg ",elapsed_time/nb_times)
136