本文整理汇总了Python中timer.time_function函数的典型用法代码示例。如果您正苦于以下问题:Python time_function函数的具体用法?Python time_function怎么用?Python time_function使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了time_function函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: enumerate
puzzles.append(d)
d = []
else:
d.append(i)
puzzles.append(d)
puzzles.pop(0)
for j,i in enumerate(puzzles):
x =[]
for k,c in enumerate(i):
d = []
for h in c:
d.append(int(h))
x.append(d)
puzzles[j] = x
f = 1
s = 0
for i in puzzles:
#print "##### ", f, " #####"
c,x = Sudoku(i)
#puzzprint(x)
s = s + c
f = f + 1
return s
from timer import time_function
print(time_function(euler96))
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:29,代码来源:96.py
示例2: palindrome_check
def palindrome_check(n):
s = str(n)
for i in range(len(s)//2 + 1):
if s[i] != s[-(i+1)]:
return False
return True
def base_check(n):
#if len(str(n)) == 1:
# return False
if palindrome_check(n) and palindrome_check(binary(n)):
return True
else:
return False
def main(N=1000000):
s = 0
for i in range(N):
if base_check(i):
#print i, binary(i), base_check
s += i
else:
pass
return s
from timer import time_function
print(time_function(main))
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:27,代码来源:36.py
示例3: range
sol.append([0 for k in range(len(temp))])
#maze = [[131,673,234,103,18],[201,96,342,965,150],[630,803,746,422,111],[537,699,497,121,956],[805,732,524,37,331]]
#sol = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
I = len(maze)
J = len(maze[0])
#print J, I
sol[0][0] = maze[0][0]
for i in range(I):
for j in range(J):
if i != I - 1:
if sol[i+1][j] == 0:
sol[i+1][j] = sol[i][j] + maze[i+1][j]
else:
if sol[i][j] + maze[i+1][j] < sol[i+1][j]:
sol[i+1][j] = sol[i][j] + maze[i+1][j]
if j != J - 1:
if sol[i][j+1] == 0:
sol[i][j+1] = sol[i][j] + maze[i][j+1]
else:
if sol[i][j] + maze[i][j+1] < sol[i][j+1]:
sol[i][j+1] = sol[i][j] + maze[i][j+1]
return sol[-1][-1]
from timer import time_function
print(time_function(solve))
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:30,代码来源:81.py
示例4: fundamental_solution
x1,y1 = fundamental_solution()
_x,_y = x1,y1
while True:
_x,_y = x1*_x + 2*y1*_y, x1*_y + y1*_x
yield _x,_y
# if t > 10^12
def f4(N):
for x,y in pell_solutions():
b = (y + 1)/2
t = (x + 1)/2
if t > N and t//1 == t and b//1 == b:
return b,t
N = 1e12
print(time_function(f4,N))
# Brute force attempts
def f(N):
T = int(N)
while True:
for r in range(1,T):
if 2*r*(r-1) == T*(T-1):
print(r,'/',T,' ',r-1,'/',T-1)
T += 1
def f1(N):
T = int(N)
while True:
P = T*(T+1)/2
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:31,代码来源:100.py
示例5: triangle_sum
def triangle_sum(x):
y = []
for i,c in enumerate(x):
dummy_row = []
if len(c) > 1:
for j,p in enumerate(c):
if j != 0 and j != (len(c) - 1):
a = p + y[-1][j]
b = p + y[-1][j-1]
if a > b:
dummy_row.append(a)
else:
dummy_row.append(b)
elif j == 0:
dummy_row.append(p + y[-1][j])
else:
dummy_row.append(p + y[-1][-1])
y.append(dummy_row)
else:
y.append(x[i])
return max(y[-1])
from timer import time_function
print(time_function(triangle_sum,x))
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:27,代码来源:18.py
示例6: d
# 31626
# 4/12/17 - rewriting
from math import sqrt
def d(n):
s = 1
for i in range(2,int(sqrt(n)) + 1):
if n%i == 0:
s += i + n//i
return s
def solve(N):
data = {}
for a in range(N):
_d = d(a)
data[a] = _d
s = []
for a in range(N):
if data[a] < N:
if data[a] != a and data[data[a]] == a:
s.append(a)
else:
if data[a] == d(data[a]):
s.append(a)
return sum(set(s))
from timer import time_function
print(time_function(solve,10000))
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:29,代码来源:21.py
示例7: enumerate
for index, pair in enumerate(histogram):
if pair[0] == item:
return index
return None
# Algorithm complexity: O(n^2)
def histogram(words):
hist = []
for word in words:
index = find(word, hist)
if index is None:
hist.append((word, 1))
else:
count = hist[index][1]
new_pair = (word, count + 1)
hist[index] = new_pair
return hist
def frequency(word, histogram):
index = find(word, histogram)
word = histogram[index][0]
return word
if __name__ == "__main__":
hist = histogram(words_list)
# timer.time_function("frequency('the', hist)") # 0.000 secs
timer.time_function("histogram(words_list)") # 9.175 secs
开发者ID:MakeSchool-17,项目名称:twitter-bot-python-beingadrian,代码行数:30,代码来源:list.py
示例8: enumerate
ab.append(k)
s = [0]*(2*ab[-1]+1)
for i,a in enumerate(ab):
for b in ab[i:]:
s[a+b] = 1
a = 0
j = 0
while j < N:
if s[j] == 0:
a += j
j += 1
return a
from timer import time_function
print(time_function(solve,28123))
"""
# Old brute force:
def factor(f):
factor = []
s = 0
for i in range(1,f//2 + 1):###<----modify to range(3,f) for primes up to f
if f%i == 0:
s = s + i
if s > f:
return True
else:
return False
def abundance_list(f):
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:31,代码来源:23.py
示例9: histogram
sys.path.append('../')
import converter
import timer
words_list = converter.convert_to_words_list("../robinson_crusoe_text.txt")
# algorithm complexity: 1 (some constant)
def histogram(words_list):
histogram = {}
for word in words_list:
try:
histogram[word] += 1
except:
histogram[word] = 0
return histogram
def frequency(word, histogram):
try:
return histogram[word]
except:
print("Word does not exist")
if __name__ == "__main__":
# histogram = histogram(words_list)
# timer.time_function("frequency('the', histogram)") # 0.000 secs
timer.time_function("histogram(words_list)") # 0.027 secs
开发者ID:MakeSchool-17,项目名称:twitter-bot-python-beingadrian,代码行数:30,代码来源:dictionary.py
示例10: range
from timer import time_function
#!/bin/sh
# P1.py
# ProjectEuler
#
# Created by joe yuan on 3/8/11.
# Copyright 2011 __MyCompanyName__. All rights reserved.
"""
# Original Solution commented out 4/4/17
sum = 0
for i in range(1001):
if i%3 == 0 or i%5 == 0:
sum = sum + i
print i
print sum
"""
def f(N):
return sum(i for i in range(1,N) if (i%3 == 0 or i%5 == 0))
print(time_function(f,1000))
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:21,代码来源:1.py
示例11: sieve
primes = sieve(int(UPPER))
mins = {k:(1e100,()) for k in range(2,N+1)}
for n in range(4,UPPER+1):
if n not in primes:
for f in gen_factors(n):
_k = len(f)
s = sum(f)
k = n - s + _k
if k > N:
continue
if n <= mins[k][0]:
mins[k] = (n,f)
return sum(set(i[0] for i in mins.values()))
from timer import time_function
print(time_function(solve))
#print(max(i[0] for i in mins.values()))
#print(sum(set(i[0] for i in mins.values())),time.time()-t)
#powers = [0]*len(primes)
#limits = [int(log(UPPER)/log(p)) for p in primes]
def inc(li,k,default=0):
m = min(li)
for i,j in enumerate(li):
if j != m:
li[i-1] += 1
li = [default]*(i-1)+li[i-1:]
return li
return [default]*(len(li)-1) + [li[-1]+1]
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:30,代码来源:88.py
示例12: enumerate
_c = C[n]
for i,n in enumerate(a[::-1]):
C[n] = _c + i + 1
mk,mv = -1,-1
for k,v in C.items():
if v > mv:
mv = v
mk = k
return mk
def solve_bf():
x = []
for i in range(1000000,0,-1):
d = []
d.append(i)
c = i
while c != 1:
if c%2 == 0:
c = c/2
else:
c = 3*c + 1
d.append(c)
x.append([len(d),d[0]])
x.sort()
return x[-1]
from timer import time_function
print(time_function(solve,int(1e6)))
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:28,代码来源:14.py
示例13: is_special
if is_special(s):
if sum(s) < m:
m = sum(s)
ms = s
# increment
last = itr[0]
itr[0] = (itr[0]-1)%(N+1)
for i in range(1,7):
if last == 0:
last = itr[i]
itr[i] = (itr[i]-1)%(N+1)
else:
break
return ''.join(str(i) for i in sorted(ms))
print(time_function(nearby_search_solve))
#print(is_special([6, 9, 11, 12, 13]))
import sys
sys.exit()
sp = [1]
N = 1
last = N
for n in range(2,7):
l = len(sp)
sp_mid = sorted(sp)[max(0,l//2)]
n0 = sum(range(1,n+1))
s0 = n*sp_mid+sum(sp)
print('n =',n)
print('sp =',sp,'sp_mid =',sp_mid,'sum(sp) =',sum(sp),'n*sp_mid =',n*sp_mid)
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:31,代码来源:103.py
示例14: count
3 + 2
3 + 1 + 1
2 + 2 + 1
2 + 1 + 1 + 1
1 + 1 + 1 + 1 + 1
How many different ways can one hundred be written as a sum of at least two positive integers?
"""
correct = {
2:1,
3:2,
4:4,
5:6,
6:10,
7:14,
}
def count(N):
sol = [1]+[0]*(N)
for i in range(1,N):
for j in range(i,N+1):
sol[j] += sol[j - i]
return sol[-1]
count(100)
from timer import time_function
print(time_function(count,100))
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:30,代码来源:76_not_fully_understood.py
示例15: word_to_num
if digit not in digits and letter not in key:
key[letter] = digit
digits.append(digit)
elif letter not in key or key[letter] != digit:
good_key = False
break
if good_key:
sq2 = word_to_num(words[1],key)
if sq2 in sqs:
f += [int(sq),int(sq2)]
if len(f) > 0:
return max(f)
except KeyError:
pass
print(time_function(solve,problem_number=98))
"""
def word_to_num(word,key):
s = ''
for e in word:
s += str(key[e])
if s[0] == '0':
raise LeadingZeroException()
return int(s)
def solve():
anagrams = sort_words()
M = max(anagrams)
for l in range(M,0,-1):
f = []
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:31,代码来源:98.py
示例16: f
from timer import time_function
from math import factorial
def f(x):
return 1 if x < 2 else x*f(x-1)
def f1(x):
return factorial(x)
N = 100000
s = 0
x = 10
for n in range(N):
s += time_function(f,x)[1]
print('x*x',s/N)
s = 0
for n in range(N):
s += time_function(f1,x)[1]
print('x**2',s/N)
开发者ID:joeyuan19,项目名称:ProjectEuler,代码行数:19,代码来源:test.py
注:本文中的timer.time_function函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论