/
test.py
executable file
·70 lines (62 loc) · 1.78 KB
/
test.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 25 14:34:04 2016
@author: devd
"""
from __future__ import division
import logging
import math
from choose import nCr
import numpy as np
from scipy.misc import comb
import createRandomString as c
import meshers
import time
import random
import functools
import json
import pickle
import os
from mesh_util import occupancySort, formatStrings, fast_q
from createRandomString import createIndependentRandomStrings
#logging.getLogger('').handlers = []
#logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
#logging.debug('This is a log message.')
#logging.info('test')
#logging.warning('double test')
#
#strings = createIndependentRandomStrings(4,10,numOnes = 2)
#new_strings = []
#for string in strings:
# new_strings.append((string, long(string, base=2)))
#print new_strings
#print "\n \n \n"
##occupancySort(strings)
#new_strings.sort(key = lambda x: x[0].count("1"))
#print new_strings
strings = createIndependentRandomStrings(256, 10000, numOnes = 5)
strings = formatStrings(strings)
occs = [x[2] for x in strings]
print np.mean(occs)
print np.std(occs)
def faster_q(length, occ1, occ2):
numerator = 1
for i in range(length-occ1, length-occ1-occ2, -1):
numerator *= i
denominator = 1
for i in range(length, length-occ2, -1):
denominator *= i
return float(numerator)/float(denominator)
length = 128
start = time.time()
for occ1 in range(0,50):
for occ2 in range(0,50):
result1 = fast_q(length, occ1, occ2)
t1 = time.time() - start
start = time.time()
for occ1 in range(0,50):
for occ2 in range(0,50):
result2 = faster_q(length, occ1, occ2)
t2 = time.time()-start
print 'fast_q got {} in {} ms'.format(result1, t1)
print 'faster_q got {} in {} ms'.format(result2, t2)