Skip to content

Commit

Permalink
docs: improve performance tips by making the example more explicit (#…
Browse files Browse the repository at this point in the history
…1139)

* docs: improve performance tips by making the example more explicit

---------

Co-authored-by: Sebastian Niehus <[email protected]>
  • Loading branch information
NiklasKoehneckeAA and SebastianNiehusAA authored Nov 19, 2024
1 parent 5e59adc commit fa16c84
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/documentation/performance_tips.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"import time\n",
"from concurrent.futures import ThreadPoolExecutor\n",
"from itertools import repeat\n",
"from typing import Any\n",
"\n",
"from intelligence_layer.core import NoOpTracer, Task, TaskSpan"
]
Expand Down Expand Up @@ -61,21 +60,21 @@
"outputs": [],
"source": [
"class DummyTask(Task):\n",
" def do_run(self, input: Any, task_span: TaskSpan) -> Any:\n",
" def do_run(self, input: str, task_span: TaskSpan) -> str:\n",
" time.sleep(2)\n",
" print(\"Task1 complete\")\n",
" return input\n",
" print(f\"Task1 complete with input: {input}\")\n",
" return input.upper()\n",
"\n",
"\n",
"tracer = NoOpTracer()\n",
"\n",
"task_input = [\"A\", \"B\", \"C\", \"D\"]\n",
"multiple_task_inputs = [f\"input-{i}\" for i in range(4)]\n",
"task = DummyTask()\n",
"\n",
"\n",
"result = task.run_concurrently(\n",
" task_input, tracer\n",
") # this finishes in 2 seconds instead of 8\n",
" multiple_task_inputs, tracer\n",
") # this finishes in 2 seconds instead of 8 when looping over the inputs\n",
"result"
]
},
Expand All @@ -96,22 +95,22 @@
"metadata": {},
"outputs": [],
"source": [
"# Second long running task\n",
"# Second long-running task\n",
"\n",
"\n",
"class DummyTask2(Task):\n",
" def do_run(self, input: Any, task_span: TaskSpan) -> Any:\n",
" def do_run(self, input: str, task_span: TaskSpan) -> str:\n",
" time.sleep(2)\n",
" print(\"Task2 complete\")\n",
" return input\n",
" print(f\"Task2 complete with input: {input}\")\n",
" return input.upper()\n",
"\n",
"\n",
"# initialize all tasks and inputs\n",
"task_1 = DummyTask()\n",
"task_2 = DummyTask2()\n",
"\n",
"task_input_1 = list(range(10))\n",
"task_input_2 = list(range(10, 20))"
"task_input_1 = list([f\"input-{i}\" for i in range(10)])\n",
"task_input_2 = list([f\"input-{i}\" for i in range(20)])"
]
},
{
Expand Down

0 comments on commit fa16c84

Please sign in to comment.