Skip to content

Instantly share code, notes, and snippets.

@pingswept
Last active March 9, 2021 16:58
Show Gist options
  • Save pingswept/1dcb087d38719a3d00b8ff7cbe4f66af to your computer and use it in GitHub Desktop.
Save pingswept/1dcb087d38719a3d00b8ff7cbe4f66af to your computer and use it in GitHub Desktop.
profiling-example.py
import cProfile
import pstats
from pysolar.solar import *
import datetime
import random
latitudes = random.sample(range(-90, 90), 100)
longitudes = random.sample(range(-180, 180), 100)
date = datetime.datetime(2007, 2, 18, 15, 13, 1, 130320, tzinfo=datetime.timezone.utc)
if __name__ == '__main__':
profiler = cProfile.Profile()
profiler.enable()
[get_altitude(lat, long, date) for lat, long in zip(latitudes, longitudes)]
profiler.disable()
stats = pstats.Stats(profiler).sort_stats('cumtime')
stats.print_stats()
stats.dump_stats('results.prof')
# Install Snakeviz to visualize results with pip3 install snakeviz
#
# Then:
# /home/pi/.local/bin/snakeviz -s -H 192.168.1.217 results.prof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment