Skip to content

Instantly share code, notes, and snippets.

@juanpaexpedite
Created June 16, 2023 06:41
Show Gist options
  • Save juanpaexpedite/08133eeb7334a3679a81b3e349910e2b to your computer and use it in GitHub Desktop.
Save juanpaexpedite/08133eeb7334a3679a81b3e349910e2b to your computer and use it in GitHub Desktop.
import timeit
import matplotlib.pyplot as plt
import winreg
# Obtener la lista de fuentes disponibles en el Registro de Windows
fonts_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", 0, winreg.KEY_READ)
font_names = [winreg.EnumValue(fonts_key, i)[0] for i in range(winreg.QueryInfoKey(fonts_key)[1])]
#Pause here to wait for loading if not I have an error finding fonts
code = """
import matplotlib.pyplot as plt
plt.text(0.5, 0.5, 'The quick brown fox jumps over the lazy dog', fontsize=12, fontname='{}')
plt.axis('off')
plt.show()
"""
# Función para medir el tiempo de renderizado de una fuente específica
def measure_render_time(font_name):
execution_time = timeit.timeit(code.format(font_name), setup='import matplotlib.pyplot as plt', number=1)
return execution_time
# Medir el tiempo de renderizado para cada fuente y almacenar los resultados en un diccionario
render_times = {}
for font_name in font_names:
render_time = measure_render_time(font_name)
render_times[font_name] = render_time
# Ordenar el diccionario por los valores (tiempos de renderizado)
sorted_render_times = sorted(render_times.items(), key=lambda x: x[1])
# Mostrar las fuentes ordenadas por tiempo de renderizado
for font_name, render_time in sorted_render_times:
print(f"FONT: {font_name}, RENDERING TIME: {render_time:.5f}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment