我写了一个代码,它应该接收一些图像并将它们变成黑白。我正在测量每个任务的响应时间(响应时间 = 接收到每个图像并变成黑白图像的时间)。这是代码:
from __future__ import print_function
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
from select import select
import socket
from struct import pack
from struct import unpack
#from collections import deque
import commands
from PIL import Image
import time
host = commands.getoutput("hostname -I")
port = 5005
backlog = 5
BUFSIZE = 4096
queueList = []
start = []
end = []
temp = []
def processP(q):
i = 0
while q:
name = q.pop(0)
col = Image.open(name)
gray = col.convert('L')
bw = gray.point(lambda x: 0 if x<128 else 255, '1')
bw.save("%d+30.jpg" % (i+1))
end.append(time.time())
#print(temp)
i = i + 1
class Receiver:
''' Buffer binary data from socket conn '''
def __init__(self, conn):
self.conn = conn
self.buff = bytearray()
def get(self, size):
''' Get size bytes from the buffer, reading
from conn when necessary
'''
while len(self.buff) < size:
data = self.conn.recv(BUFSIZE)
if not data:
break
self.buff.extend(data)
# Extract the desired bytes
result = self.buff[:size]
# and remove them from the buffer
del self.buff[:size]
return bytes(result)
def save(self, fname):
''' Save the remaining bytes to file fname '''
with open(fname, 'wb') as f:
if self.buff:
f.write(bytes(self.buff))
while True:
data = self.conn.recv(BUFSIZE)
if not data:
break
f.write(data)
现在出于某些评估目的,我多次发送单个图像。当我查看响应时间时,我发现有时第 8 个图像的响应时间比第 9 个图像的响应时间更长。
所以我的问题是,由于处理每个图像所需的大小和时间都相同(我多次发送单个图像),为什么每个图像的响应时间是变量?下一个图像的响应时间不应该比前一个更长(或至少相等)(例如,第 4 个图像的响应时间 > 第 3 个图像的响应时间)?
阿晨1998
相关分类