from time import time
import random, bisect
import numpy

nelem = 8191180
bits64 = 2**63
random.seed(1)

print "Creating the lists..."
t1 = time()
id1 = numpy.empty(nelem, dtype='i8')
id1[:] = numpy.random.rand(nelem)*bits64
str2 = numpy.empty(nelem, dtype='S30')
str2[:] = "This is a bunch of text..."
print "Time for lists creation:", round(time()-t1, 3)
print "Sorting..."
t1 = time()
sid = numpy.sort(id1)
revid = id1.argsort()
print "Time for sorting:", round(time()-t1, 3)

print "Timing queries..."
t1 = time()
for i in xrange(nelem):
    pos = bisect.bisect_left(sid, id1[random.randint(0, nelem-1)])
    idx = revid[pos]
    t = str2[idx]
print "Time for querying:", round(time()-t1, 3)
