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

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