{ "cells": [ { "cell_type": "markdown", "id": "c40c06a2", "metadata": {}, "source": [ "# Performance measurements\n", "This notebook tries to push a number of frames to the browser as fast as posisble, using different parameters, and measures how fast it goes." ] }, { "cell_type": "code", "execution_count": null, "id": "fd3aa015", "metadata": {}, "outputs": [], "source": [ "import time\n", "import numpy as np\n", "from jupyter_rfb import RemoteFrameBuffer\n", "\n", "class PerformanceTester(RemoteFrameBuffer):\n", " i = 0\n", " n = 0\n", " \n", " def get_frame(self):\n", " if self.i >= self.n:\n", " return None\n", " array = np.zeros((640, 480), np.uint8)\n", " # array = np.random.uniform(0, 255, (640, 480)).astype(np.uint8)\n", " array[:20,: int(array.shape[1] * (self.i + 1) / self.n)] = 255\n", " self.i += 1\n", " self.request_draw() # keep going\n", " return array\n", "\n", " def run(self, n=100):\n", " self.i = 0\n", " self.n = n\n", " self.request_draw()\n", " \n", "w = PerformanceTester(css_height='100px')" ] }, { "cell_type": "code", "execution_count": null, "id": "6ea1d044", "metadata": {}, "outputs": [], "source": [ "w" ] }, { "cell_type": "code", "execution_count": null, "id": "cbc00754", "metadata": {}, "outputs": [], "source": [ "n = 50\n", "w.max_buffered_frames = 2\n", "w.reset_stats()\n", "w.run(n)" ] }, { "cell_type": "code", "execution_count": null, "id": "4b7c7dd0", "metadata": {}, "outputs": [], "source": [ "# Call this when it's done\n", "w.get_stats()" ] }, { "cell_type": "code", "execution_count": null, "id": "c77e31a0", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.9" } }, "nbformat": 4, "nbformat_minor": 5 }