Skip to content

Commit

Permalink
Merge pull request #31 from Alphagon/s3-loader2
Browse files Browse the repository at this point in the history
Add S3 File and Folder Operations in S3FileHandler Class
  • Loading branch information
sizhky authored Oct 16, 2024
2 parents bc99bbb + c9b820c commit e32ed25
Show file tree
Hide file tree
Showing 3 changed files with 813 additions and 6 deletions.
18 changes: 12 additions & 6 deletions nbs/profiler.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,28 @@
"# | export\n",
"# | hide\n",
"\n",
"def time_profiler(filename='profiling_results.txt'):\n",
"\n",
"def time_profiler(filename=\"profiling_results.txt\"):\n",
" # The outer function that allows customization of the filename\n",
" def decorator(func):\n",
" # The middle function which receives the function to be wrapped\n",
" def wrapper(*args, **kwargs):\n",
" # The inner function that actually runs the profiling\n",
" profiler = cProfile.Profile()\n",
" profiler.enable() # Start profiling\n",
" profiler.enable() # Start profiling\n",
" result = func(*args, **kwargs)\n",
" profiler.disable() # End profiling\n",
" profiler.disable() # End profiling\n",
" # Create a StringIO stream to capture profiling results\n",
" s = StringIO()\n",
" ps = pstats.Stats(profiler, stream=s).sort_stats('cumulative')\n",
" ps = pstats.Stats(profiler, stream=s).sort_stats(\"cumulative\")\n",
" ps.print_stats()\n",
" # Write the profiling results to the specified file\n",
" with open(filename, 'w') as f:\n",
" with open(filename, \"w\") as f:\n",
" f.write(s.getvalue())\n",
" return result\n",
"\n",
" return wrapper\n",
"\n",
" return decorator"
]
},
Expand Down Expand Up @@ -95,21 +98,24 @@
" total += i\n",
" return total\n",
"\n",
"\n",
"def inner_function_2():\n",
" # Simulating some different work, like squaring numbers\n",
" total = 0\n",
" for i in range(10000000):\n",
" total += i * i\n",
" return total\n",
"\n",
"@time_profiler('outer_function_profile.txt')\n",
"\n",
"@time_profiler(\"outer_function_profile.txt\")\n",
"def outer_function():\n",
" result_1 = inner_function_1()\n",
" print(f\"Result from inner_function_1: {result_1}\")\n",
"\n",
" result_2 = inner_function_2()\n",
" print(f\"Result from inner_function_2: {result_2}\")\n",
"\n",
"\n",
"# Call the outer function\n",
"outer_function()"
]
Expand Down
Loading

0 comments on commit e32ed25

Please sign in to comment.