How to specify setup code with Runner.bench_func() ?
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- performance, tooling
Línea de trabajo
Comienza con Runner.bench_func() y el comportamiento de subprocess(main) mostrado en el ejemplo proporcionado; lee también el issue relacionado 28. Reproduce la construcción repetida de BenchModule y, a continuación, verifica que el setup solicitado se ejecute una vez a lo largo de las ejecuciones de los benchmarks, mientras los benchmarks siguen ejecutándose normalmente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I am trying to bench some data structures with a large number of items in each structure. I would like to have a single setup that is called once (and only once) for all benchmark runs, because the setup takes several seconds to complete.
While debugging, I discovered this very peculiar behavior that perf reloads the entire main module for each run.
import perf
import time
def run_benchmarks(module):
runner = perf.Runner()
def get_doc(attr):
return getattr(module, attr).__doc__
bench_names = sorted([ x for x in dir(module) if x.startswith('bench_') ], key=get_doc)
for bench_name in bench_names:
bench = getattr(module, bench_name)
doc = bench.__doc__
print('Running: %s' % (doc))
runner.bench_func(doc, bench)
class BenchModule(object):
def __init__(self):
print('Creating BenchModule()')
time.sleep(3)
print('Created BenchModule()')
def bench_foo(self):
'''Benchmark: foo'''
return list(range(1000))
def bench_bar(self):
'''Benchmark: bar'''
return list(range(1000))
if __name__ == '__main__':
print('Starting benchmarks')
module = BenchModule()
run_benchmarks(module)
When I run this, I see output like the following:
Starting benchmarks
Creating BenchModule()
Created BenchModule()
Running: Benchmark: bar
Starting benchmarks
Creating BenchModule()
Created BenchModule()
Running: Benchmark: bar
Running: Benchmark: foo
.Starting benchmarks
Creating BenchModule()
Created BenchModule()
Running: Benchmark: bar
Running: Benchmark: foo
.Starting benchmarks
Creating BenchModule()
Created BenchModule()
Running: Benchmark: bar
Running: Benchmark: foo
.Starting benchmarks
Creating BenchModule()
[ ... snip ... ]
.Starting benchmarks
Creating BenchModule()
Created BenchModule()
Running: Benchmark: bar
Running: Benchmark: foo
.
Benchmark: foo: Mean +- std dev: 9.83 us +- 0.16 us
... what the ? 😖
Why is it printing my Starting benchmarks line more than once? More importantly, how is it doing this? Is there some black magic going on with subprocess(__main__)?
But back to the original issue that lead me down this rathole; how do I prevent perf from running my BenchModule constructor on each run? I put a 3-second sleep in there to illustrate why the current behavior is obnoxious. In my real world benchmark, the setup time is more than 30 seconds, and running the complete test suite lasts a few hours.
This is possibly related: https://github.com/vstinner/perf/issues/28
- Lenguaje dominante
- Python
- Estrellas
- 967
- Forks
- 112
- Merge medio
- 5 d 8 h
- PR fusionados (30 d)
- 9
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de psf/pyperf
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
psf/pyperf#274 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
Improve Type System for `pyperf`Posiblemente ocupada @DebanKsahu la tomó hace 69 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
psf/pyperf#255 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 32/100
psf/pyperf#243 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Extend hook's teardown metadata with warmup/calibration flagsPosiblemente ocupada @maurycy la tomó hace 170 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
psf/pyperf#239 · 12 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
psf/pyperf#216 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de psf/pyperf
Issues similares
-
add entry to blockAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
StevenBlack/hosts#3299 ·
-
`garak --report` overwrites the input report when its name has no ".report"Posiblemente ocupada @0z5a la tomó hoy. Abiertoneeds-triage
Dificultad 2/5 Medio día Aptitud para principiantes 72/100
Los mantenedores suelen responder en 2 días
-
plot_graph crashes when a mesh node has no m2m edgePosiblemente ocupada @tygvi la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
mllam/neural-lam#883 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
future-agi/future-agi#4092 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
transcript analytics: a text whose only protected spans the prose pass redacts is withheld wholeAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
WingedGuardian/GENesis-AGI#4641 ·
Los mantenedores suelen responder en 1 día