Skip to content

Commit

Permalink
Tested performance of refactored CI (increased by 30 times)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuliivasilev committed Aug 3, 2024
1 parent aafccaf commit 7f143e4
Showing 1 changed file with 72 additions and 27 deletions.
99 changes: 72 additions & 27 deletions demonstration/Articles/Refactoring.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
"cells": [
{
"cell_type": "code",
"execution_count": 27,
"id": "7ca4db35",
"execution_count": 78,
"id": "374b961a",
"metadata": {},
"outputs": [],
"source": [
"from lifelines.utils import concordance_index"
"from lifelines.utils import concordance_index\n",
"from numba import njit, jit"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fc02d133",
"id": "9a9f032a",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -109,7 +110,7 @@
{
"cell_type": "code",
"execution_count": 22,
"id": "fb905b58",
"id": "17768980",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -157,11 +158,12 @@
},
{
"cell_type": "code",
"execution_count": 66,
"id": "47b7fb0d",
"execution_count": 79,
"id": "eb902005",
"metadata": {},
"outputs": [],
"source": [
"@njit\n",
"def concordance_index_self(T, P, E):\n",
" \"\"\"\n",
" Calculates the concordance index (C-index) for survival analysis.\n",
Expand Down Expand Up @@ -197,8 +199,8 @@
},
{
"cell_type": "code",
"execution_count": 67,
"id": "0547a83f",
"execution_count": 80,
"id": "3e4acf25",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -211,7 +213,7 @@
{
"cell_type": "code",
"execution_count": 71,
"id": "b529d42e",
"id": "7ab1c5b3",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -225,39 +227,82 @@
},
{
"cell_type": "code",
"execution_count": 72,
"id": "314a5f66",
"execution_count": 81,
"id": "6995ee3e",
"metadata": {},
"outputs": [],
"source": [
"def test_f(f):\n",
" a = 0\n",
" for i in range(1000):\n",
" a = np.random.rand(100)*100\n",
" b = np.random.rand(100)*100\n",
" e = np.round(np.random.rand(100))\n",
" a += f(a, b, e)\n",
" return a"
]
},
{
"cell_type": "code",
"execution_count": 82,
"id": "64fde2e0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(0.5041072200605274, 0.5041072200605274)"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"672 ms ± 2.16 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
"source": [
"concordance_index(a, b, e)"
"%timeit test_f(concordance_index)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2e6df15a",
"execution_count": 83,
"id": "85e2e7b0",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"22.9 ms ± 197 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
"source": [
"%timeit test_f(concordance_index_self)"
]
},
{
"cell_type": "code",
"execution_count": 84,
"id": "91add654",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"29.344978165938866"
]
},
"execution_count": 84,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"concordance_index_self(a, b, e)"
"672/22.9"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "7af657dc",
"id": "08d95f7f",
"metadata": {},
"outputs": [
{
Expand All @@ -280,7 +325,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a4d58b6d",
"id": "69e4e1bf",
"metadata": {},
"outputs": [],
"source": []
Expand Down

0 comments on commit 7f143e4

Please sign in to comment.