Charles Sounder
Charles Sounder

Reputation: 591

Gevent vs sync processing for scanning, why are they approximately the same speed?

def cn(host, port):
    try:
        conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        conn.connect((host, port))
        print '[+]%d/tcp open' % port
        conn.close()
    except:
        pass
        #print '[-]%d/tcp closed' % port

def ge():
    st = time.time()

    threads = [gevent.spawn(cn, '127.0.0.1', i) for i in xrange(1000)]
    gevent.joinall(threads)

    print "using gevent - " + str(time.time() - st)

def ss():
    st = time.time()

    for i in range(1, 1000):
        connScan('127.0.0.1', i)

    print "using sync processing - " + str(time.time() - st)

Gevent is just a tad bit faster than sync processing. Why?

Is it possible to improve the above code to make it faster using gevent?

Upvotes: 1

Views: 210

Answers (1)

bav
bav

Reputation: 1623

The most ports are closed so there is no blocking at all to get speedup from gevent version.

Upvotes: 1

Related Questions