diff --git a/src/documentation/performance_tips.ipynb b/src/documentation/performance_tips.ipynb index ca065a9c..f6a99e47 100644 --- a/src/documentation/performance_tips.ipynb +++ b/src/documentation/performance_tips.ipynb @@ -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" ] @@ -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" ] }, @@ -100,18 +99,18 @@ "\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)])" ] }, {