{ "cells": [ { "cell_type": "markdown", "id": "21055180-8634-4816-a561-825c22b3b391", "metadata": {}, "source": [ "https://twitter.com/julia_kizi/status/1400703388363468801" ] }, { "cell_type": "code", "execution_count": 1, "id": "14975a5d-f4c4-415b-a107-8f5bf69896aa", "metadata": {}, "outputs": [], "source": [ "using BenchmarkHistograms" ] }, { "cell_type": "code", "execution_count": 2, "id": "b15a4783-c8aa-4b22-b91d-90d793f67261", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "g (generic function with 1 method)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = randn(10^5)\n", "\n", "f(A) = min(A...)\n", "g(A) = minimum(A)" ] }, { "cell_type": "code", "execution_count": 3, "id": "98b74adc-6085-4e30-b437-ac89059f775b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "samples: 877; evals/sample: 1; memory estimate: 5.34 MiB; allocs estimate: 200003\n", "ns\n", "\n", " (4.48e6 - 5.08e6 ] \u001b[32m████████▉\u001b[39m154\n", " (5.08e6 - 5.69e6 ] \u001b[32m██████████████████████████████ \u001b[39m523\n", " (5.69e6 - 6.29e6 ] \u001b[32m████\u001b[39m68\n", " (6.29e6 - 6.9e6 ] \u001b[32m█▌\u001b[39m24\n", " (6.9e6 - 7.5e6 ] \u001b[32m█▎\u001b[39m20\n", " (7.5e6 - 8.1e6 ] \u001b[32m██\u001b[39m33\n", " (8.1e6 - 8.71e6 ] \u001b[32m█▌\u001b[39m24\n", " (8.71e6 - 9.31e6 ] \u001b[32m█\u001b[39m17\n", " (9.31e6 - 9.92e6 ] \u001b[32m▋\u001b[39m10\n", " (9.92e6 - 1.052e7] \u001b[32m▏\u001b[39m2\n", " (1.052e7 - 1.113e7] \u001b[32m▏\u001b[39m2\n", "\n", " Counts\n", "\n", "min: 4.475 ms (0.00% GC); mean: 5.690 ms (6.20% GC); median: 5.306 ms (0.00% GC); max: 11.130 ms (0.00% GC)." ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "@benchmark f($A)" ] }, { "cell_type": "code", "execution_count": 4, "id": "d3b3f35c-e2cf-4377-b49f-15c240dfd407", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "samples: 10000; evals/sample: 1; memory estimate: 0 bytes; allocs estimate: 0\n", "ns\n", "\n", " (48100.0 - 53500.0 ] \u001b[32m██████████████████████████████ \u001b[39m8101\n", " (53500.0 - 58900.0 ] \u001b[32m███▏\u001b[39m814\n", " (58900.0 - 64300.0 ] \u001b[32m▎\u001b[39m64\n", " (64300.0 - 69700.0 ] \u001b[32m█▍\u001b[39m346\n", " (69700.0 - 75100.0 ] \u001b[32m█▎\u001b[39m319\n", " (75100.0 - 80500.0 ] \u001b[32m▏\u001b[39m29\n", " (80500.0 - 85900.0 ] \u001b[32m▌\u001b[39m102\n", " (85900.0 - 91200.0 ] \u001b[32m▋\u001b[39m146\n", " (91200.0 - 96600.0 ] \u001b[32m▏\u001b[39m29\n", " (96600.0 - 102000.0] \u001b[32m▏\u001b[39m12\n", " (102000.0 - 107400.0] \u001b[32m▏\u001b[39m15\n", " (107400.0 - 112800.0] \u001b[32m▏\u001b[39m8\n", " (112800.0 - 118200.0] \u001b[32m▏\u001b[39m2\n", " (118200.0 - 123600.0] \u001b[32m▏\u001b[39m3\n", " (123600.0 - 164600.0] \u001b[32m▏\u001b[39m10\n", "\n", " Counts\n", "\n", "min: 48.100 μs (0.00% GC); mean: 54.065 μs (0.00% GC); median: 51.700 μs (0.00% GC); max: 164.600 μs (0.00% GC)." ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "@benchmark g($A)" ] }, { "cell_type": "code", "execution_count": null, "id": "af3040bf-966e-4db1-a352-f3f516c6965c", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "formats": "ipynb,md" }, "kernelspec": { "display_name": "Julia 1.7.0-DEV", "language": "julia", "name": "julia-1.7" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.7.0" } }, "nbformat": 4, "nbformat_minor": 5 }