@SureshPatil/

ClientsideOilyRatio

Python 2.7

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from primefac import *
import random
import time



def run_trial(n):
  print 'Between 2 to the', n - 1, 'th and 2 to the', n, 'th power' 
  y = random.randint(2**(n-1), 2**n)
  start = time.clock()
  primes = []
  for x in range(2):
    x = nextprime(y)
    primes.append(x)
    y = x + 1
  end = time.clock()
  findPrimeTime = end - start
  print('Found Primes', primes[0], 'and', primes[1])
  product = primes[0] * primes[1]
  print('Product', product)
  start = time.clock()
  x = factorint(product)
  end = time.clock()
  factorTime = end - start
  print('Factored to', x)
  print('Finding primes took', findPrimeTime)
  print('Finding product took', factorTime)


def run_multiple_trial(n, numTrials):
  print 'Between 2 to the', n - 1, 'th and 2 to the', n, 'th power' 
  findPrimeTimes = []
  factorTimes = []
  for trial in range(numTrials):  
    start = time.clock()
    primes = []
    for x in range(2):
      y = random.randint(2**(n-1), 2**n)
      x = nextprime(y)
      primes.append(x)
    end = time.clock()
    findPrimeTimes.append(end - start)
    product = primes[0] * primes[1]
    start = time.clock()
    x = factorint(product)
    end = time.clock()
    factorTimes.append(end - start)
  print('Average prime generation time', sum(findPrimeTimes)/len(findPrimeTimes))
  print('Average time to factor', sum(factorTimes)/len(factorTimes))


# run_multiple_trial(33,1