After restarting the computer, the transfer speed dropped.

Hello ! I am writing a small test UDP server. Before restarting the computer, the packet transfer rate was more than 12 Mb / s, after rebooting the speed dropped to 4 Mb / s. I tried different settings, reinstalled Windows, but all this did not help. Please help.


import socket
import optparse
import time
import sys
import ctypes, os 

# Address information of the target (use a broadcast address)
IPADDR = '192.168.0.1'
PORTNUM = 50007
PACKETDATA = 'Hello!'

# Length of packet
PACKETL = 1400
STARTSPEED = 10
def micros():
    "return a timestamp in microseconds (us)"
    tics = ctypes.c_int64()
    freq = ctypes.c_int64()

    #get ticks on the internal ~2MHz QPC clock
    ctypes.windll.Kernel32.QueryPerformanceCounter(ctypes.byref(tics)) 
    #get the actual freq. of the internal ~2MHz QPC clock
    ctypes.windll.Kernel32.QueryPerformanceFrequency(ctypes.byref(freq))  

    t_us = tics.value*1e6/freq.value
    return t_us

def millis():
    "return a timestamp in milliseconds (ms)"
    tics = ctypes.c_int64()
    freq = ctypes.c_int64()

    #get ticks on the internal ~2MHz QPC clock
    ctypes.windll.Kernel32.QueryPerformanceCounter(ctypes.byref(tics)) 
    #get the actual freq. of the internal ~2MHz QPC clock 
    ctypes.windll.Kernel32.QueryPerformanceFrequency(ctypes.byref(freq)) 

    t_ms = tics.value*1e3/freq.value
    return t_ms
    
def delayMicroseconds(delay_us):
    "delay for delay_us microseconds (us)"
    t_start = micros()
    while (micros() - t_start < delay_us):
      pass #do nothing 
    return 

        
def echo_server(host, port):
    print ("TCP send file server")	    
    datain=0
    data_len=0
    delays=STARTSPEED
    t_time = time.monotonic()
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
    # s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    s.connect((IPADDR, PORTNUM))        

    if s is None:
        sys.exit(1)

    while 1:
        print ("Sending to: %s:"%(IPADDR))
        t_cur=time.monotonic()-t_time
        
        f = open ("test.iso", "rb")
        ls = 0
        l = f.read(PACKETL)
        data_len = 0
        timpass = 0
        try:
            while (l):
                timpass = timpass +1
                data_len = data_len + len(l)                
                s.send(l)
                delayMicroseconds(delays);
                #s.send(PACKETDATA.encode())
                l = f.read(PACKETL)
                if timpass>10:
                    t_cur=time.monotonic()-t_time                
                    timpass=0
                    if t_cur>1:
                        t_time = time.monotonic()
                        speed=data_len/t_cur
                        formatted_float = "{:.2f} ".format(speed/1000000) + "{:.2f} ".format(ls)
                        print(formatted_float)
                        # delays=delays-1
                        ls = ls + data_len
                        data_len = 0
        except KeyboardInterrupt:
            print( "Closing Connection")
            s.close()
            s = None
            f.close()
            sys.exit(1)

        s.close()

if __name__ == '__main__':
    parser = optparse.OptionParser()
    parser.add_option("-p", "--port", dest="port", type="int", default=50007, help="Port to listen on [default: %default].")
    parser.add_option("--hostname", dest="hostname", default="", help="Hostname to listen on.")

    (options, args) = parser.parse_args()

    echo_server(options.hostname, options.port)