|
6 | 6 |
|
7 | 7 |
|
8 | 8 | def get_cell(seconds): |
9 | | - cell = ', { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "time.sleep(' + str(seconds) + ')\\n", "t1 = time.time()\\n", "log += str(t1 - t0) + \'\\\\n\'\\n", "t0 = t1" ] }' |
| 9 | + cell = ', { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], ' |
| 10 | + '"source": [ "time.sleep(' + str(seconds) + ')\\n", "t1 = time.time()\\n", "log += ' |
| 11 | + 'str(t1 - t0) + \'\\\\n\'\\n", "t0 = t1" ] }' |
10 | 12 | return cell |
11 | 13 |
|
| 14 | + |
12 | 15 | def get_ipynb(cell_nb, sleep_per_cell, result_dir): |
13 | | - ipynb = '{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import uuid\\n", "import time\\n", "fname = str(uuid.uuid4()) + \'.log\'\\n", "log = \'\'\\n", "t0 = time.time()" ] }' |
| 16 | + ipynb = '{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs"' |
| 17 | + ': [], "source": [ "import uuid\\n", "import time\\n", "fname = str(uuid.uuid4()) + \'' |
| 18 | + '.log\'\\n", "log = \'\'\\n", "t0 = time.time()" ] }' |
14 | 19 | for i in range(cell_nb): |
15 | 20 | cell = get_cell(sleep_per_cell) |
16 | 21 | ipynb += cell |
17 | | - ipynb += ', { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "with open(\'' + result_dir + '/\' + fname, \'w\') as f:\\n", " f.write(log)" ] }' |
18 | | - ipynb += ' ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.1" } }, "nbformat": 4, "nbformat_minor": 4 }' |
| 22 | + ipynb += ', { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], ' |
| 23 | + '"source": [ "with open(\'' + result_dir + '/\' + fname, \'w\') as f:\\n", " ' |
| 24 | + 'f.write(log)" ] }' |
| 25 | + ipynb += ' ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", ' |
| 26 | + '"name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", ' |
| 27 | + '"version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python"' |
| 28 | + ', "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.1" } }' |
| 29 | + ', "nbformat": 4, "nbformat_minor": 4 }' |
19 | 30 | return ipynb |
20 | 31 |
|
| 32 | + |
21 | 33 | def test_performance(): |
22 | 34 | sleep_per_cell = 0.1 # each cell sleeps for that amount of seconds |
23 | 35 | cell_nb = 100 # each notebook consists of so many cells |
@@ -52,13 +64,13 @@ def test_performance(): |
52 | 64 | i = 0 |
53 | 65 | exec_time = cell_nb * sleep_per_cell # notebook execution time |
54 | 66 | launch_time = client_nb * 0.5 # kernel takes about 0.5s to launch |
55 | | - min_time = launch_time + exec_time # theoretical time for all notebooks to execute |
| 67 | + # min_time = launch_time + exec_time # theoretical time for all notebooks to execute |
56 | 68 | timeout_time = launch_time + 2 * exec_time # timeout allows slow machines to finish |
57 | 69 | while not done: |
58 | 70 | time.sleep(1) |
59 | 71 | done = True |
60 | 72 | i += 1 |
61 | | - #print(i, '/', min_time) |
| 73 | + # print(i, '/', min_time) |
62 | 74 | for client in clients: |
63 | 75 | if client.poll() is None: |
64 | 76 | done = False |
|
0 commit comments