mirror of https://github.com/scrapy/scrapy.git
profiling: fix priority distribution and add new ones
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%401001
This commit is contained in:
parent
2e63ef60f1
commit
bd1be0ac67
|
|
@ -8,7 +8,7 @@ from pq_classes import *
|
|||
|
||||
TESTID = os.getpid()
|
||||
|
||||
TESTCASES = [
|
||||
TESTCASES = (
|
||||
("heapq", PriorityQueue1),
|
||||
#("heapq+int", PriorityQueue1b),
|
||||
("dict+deque", PriorityQueue2),
|
||||
|
|
@ -18,7 +18,7 @@ TESTCASES = [
|
|||
#('list+deque', PriorityQueue5),
|
||||
('list+deque+cache', PriorityQueue5b),
|
||||
#('list+deque+cache+islice', PriorityQueue5c),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
stmt_fmt = """
|
||||
|
|
@ -44,20 +44,37 @@ with open('%(samplefile)s') as samples:
|
|||
randomprio.append(prio)
|
||||
"""
|
||||
|
||||
# def gen_random_priority(priorities):
|
||||
# return int(random.random() * priorities) - (priorities / 2)
|
||||
|
||||
def _distribution(priorities, distribution):
|
||||
half = priorities // 2
|
||||
prio = -priorities
|
||||
while not (-half <= prio <= half):
|
||||
prio = round(distribution())
|
||||
return min(max(prio, -half), half)
|
||||
|
||||
def normal_priority(priorities):
|
||||
sigma = priorities / 4.0
|
||||
dist = lambda: random.normalvariate(mu=0, sigma=sigma)
|
||||
return _distribution(priorities, dist)
|
||||
|
||||
def gauss_priority(priorities):
|
||||
sigma = priorities / 4.0
|
||||
dist = lambda: random.gauss(mu=0, sigma=sigma)
|
||||
return _distribution(priorities, dist)
|
||||
|
||||
def triangular_priority(priorities):
|
||||
half = priorities // 2
|
||||
return random.triangular(-half-1, half+1, 0)
|
||||
|
||||
def uniform_priority(priorities):
|
||||
return int(random.random() * priorities) - (priorities / 2)
|
||||
|
||||
def normal_priority(priorities):
|
||||
prio = int(random.normalvariate(priorities/2, priorities/4)) - (priorities / 2)
|
||||
return min(max(prio, -priorities/2), priorities/2)
|
||||
|
||||
|
||||
PRIORITY_DISTRIBUTIONS = {
|
||||
'uniform': uniform_priority,
|
||||
'normal': normal_priority,
|
||||
'gauss': gauss_priority,
|
||||
'triangular': triangular_priority,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -71,7 +88,7 @@ def gen_samples(count, priorities, priority_distribution=uniform_priority):
|
|||
return fn
|
||||
|
||||
def runtests(pushpops=50*1000, times=30, priorities=1, samplefile=None, priority_distribution=uniform_priority):
|
||||
samplefile = samplefile or gen_samples(pushpops, priorities)
|
||||
samplefile = samplefile or gen_samples(pushpops, priorities, priority_distribution)
|
||||
|
||||
print "\n== With %s priorities (%s) ==\n" % (priorities, samplefile)
|
||||
print "pushpops = %s, times = %s" % (pushpops, times)
|
||||
|
|
|
|||
Loading…
Reference in New Issue