from timeit import default_timer as timer
from threading import Thread
####from multiprocessing import Process as Thread
import os

# for ideone.com
class NullFile:
    def write(self, data):
        pass
devnull = NullFile()
#

def printNumbers(lowEnd, highEnd):
    while(lowEnd <= highEnd):
        print(repr(lowEnd),file=devnull)
        lowEnd += 1


countTo = 100000

#Test using 1 thread.
startSingleThread = timer()
printNumbers(0,countTo)
elapsedSingleThread = (timer() - startSingleThread)

#Test using 10 threads
numberOfThreads      = 10
countAmountPerThread = countTo//numberOfThreads

startTenThread = timer()
threads = []
for i in range(numberOfThreads):
    threadLowEnd  = i*countAmountPerThread
    threadHighEnd = (i+1)*countAmountPerThread
    t = Thread(target=printNumbers, args=(threadLowEnd,threadHighEnd,))
    threads.append(t)
    t.daemon = True
    t.start()

#Join all existing threads to main thread.
for t in threads: t.join()

elapsedTenThread = (timer() - startTenThread)

print("Time for 1 thread: " + repr(elapsedSingleThread))
print("time for 10 threads: " + repr(elapsedTenThread))
