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

Private GIT Repository
up
[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=100
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, "JPEG", 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 t = time.time()
55 for i in range(nb_times):
56
57     im.save("lena2.jpg",quality=quality)
58 elapsed_time += time.time() - t
59
60 print("time noscale jpg",elapsed_time/nb_times)
61
62
63
64 elapsed_time=0
65 t = time.time()
66 for i in range(nb_times):
67     im2=im.resize((256, 256))
68     im2.save("lena3.jpg",quality=quality)
69 elapsed_time += time.time() - t
70 print("time resize + pil",elapsed_time/nb_times)
71
72
73
74
75
76
77 with s:
78     sbuf = buffer.Buffer(s)
79
80
81     elapsed_time=0
82     t=time.time()
83     file_name="lena.bmp"
84     for i in range(nb_times):
85 #        print(file_name)
86         sbuf.put_utf8(file_name)
87
88         file_size = os.path.getsize(file_name)
89         sbuf.put_utf8(str(file_size))
90
91         with open(file_name, 'rb') as f:
92             sbuf.put_bytes(f.read())
93 #        print('File Sent')
94     elapsed_time += time.time() - t    
95     print("send lena.bmp ",elapsed_time/nb_times)
96
97     elapsed_time=0
98     t=time.time()
99     file_name="lena2.jpg"
100     for i in range(nb_times):
101  #       print(file_name)
102         sbuf.put_utf8(file_name)
103
104         file_size = os.path.getsize(file_name)
105         sbuf.put_utf8(str(file_size))
106
107         with open(file_name, 'rb') as f:
108             sbuf.put_bytes(f.read())
109  #       print('File Sent')
110     elapsed_time += time.time() - t    
111     print("send noscale lena2.jpg ",elapsed_time/nb_times)
112
113     elapsed_time=0
114     t=time.time()
115     file_name="lena3.jpg"
116     for i in range(nb_times):
117  #       print(file_name)
118         sbuf.put_utf8(file_name)
119
120         file_size = os.path.getsize(file_name)
121         sbuf.put_utf8(str(file_size))
122
123         with open(file_name, 'rb') as f:
124             sbuf.put_bytes(f.read())
125  #       print('File Sent')
126     elapsed_time += time.time() - t    
127     print("send scale lena3.jpg ",elapsed_time/nb_times)
128