]> AND Private Git Repository - Cipher_code.git/blobdiff - 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
index b96dbd30010552978f5b50c65fe957f4e6ec2088..a070da9908e14acfe75dc4c9be47bd4ff2305dbd 100644 (file)
 import socket
 import threading
 import os
 import socket
 import threading
 import os
-
+import time
 import buffer
 import buffer
+from PIL import Image
+import sys
+from io import BytesIO
 
 
-HOST = 'bilbo'
+HOST = "192.168.0.106"
 PORT = 2345
 
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.connect((HOST, PORT))
 
 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("time in memory bmp",elapsed_time/nb_times)
+
+
+"""
+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("time noscale jpg",elapsed_time/nb_times)
+
+
+
+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("time resize + pil",elapsed_time/nb_times)
+
+
+
+
+
+
 with s:
     sbuf = buffer.Buffer(s)
 
 
 with s:
     sbuf = buffer.Buffer(s)
 
 
-#    files = input('Enter file(s) to send: ')
- #   files_to_send = files.split()
-    file_name="lena.jpg"
-    for i in range(10):
-#    for file_name in files_to_send:
-        print(file_name)
+    elapsed_time=0
+    t=time.time()
+    file_name="lena.bmp"
+    for i in range(nb_times):
+#        print(file_name)
+        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())
+#        print('File Sent')
+    elapsed_time += time.time() - t    
+    print("send lena.bmp ",elapsed_time/nb_times)
+
+    elapsed_time=0
+    t=time.time()
+    file_name="lena2.jpg"
+    for i in range(nb_times):
+ #       print(file_name)
         sbuf.put_utf8(file_name)
 
         file_size = os.path.getsize(file_name)
         sbuf.put_utf8(file_name)
 
         file_size = os.path.getsize(file_name)
@@ -27,6 +112,23 @@ with s:
 
         with open(file_name, 'rb') as f:
             sbuf.put_bytes(f.read())
 
         with open(file_name, 'rb') as f:
             sbuf.put_bytes(f.read())
-        print('File Sent')
+ #       print('File Sent')
+    elapsed_time += time.time() - t    
+    print("send noscale lena2.jpg ",elapsed_time/nb_times)
+
+    elapsed_time=0
+    t=time.time()
+    file_name="lena3.jpg"
+    for i in range(nb_times):
+ #       print(file_name)
+        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())
+ #       print('File Sent')
+    elapsed_time += time.time() - t    
+    print("send scale lena3.jpg ",elapsed_time/nb_times)