{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "5a8482cc-070f-4f4e-a320-d7ad1ac3ab94", "metadata": {}, "outputs": [], "source": [ "using Profile\n", "using ProfileCanvas\n", "using BenchmarkTools" ] }, { "cell_type": "code", "execution_count": 2, "id": "70ee215f-5b4c-44fa-9477-845b39b1b2da", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.000074 seconds (104 allocations: 15.984 KiB)\n", " 0.000048 seconds (104 allocations: 15.984 KiB)\n", " 0.000047 seconds (104 allocations: 15.984 KiB)\n", " 32.700 μs (104 allocations: 15.98 KiB)\n" ] } ], "source": [ "using Distributions\n", "\n", "function sim_t_test(; dist = Normal(), n = 10, μ = mean(dist), L = 10^5)\n", " pval = Float64[]\n", " for _ in 1:L\n", " X = rand(dist, n)\n", " X̄ = mean(X)\n", " S = std(X)\n", " t = √n * (X̄ - μ)/S\n", " p = 2ccdf(TDist(n-1), abs(t))\n", " push!(pval, p)\n", " end\n", " pval\n", "end\n", "\n", "pval = @time sim_t_test(L=100)\n", "pval = @time sim_t_test(L=100)\n", "pval = @time sim_t_test(L=100)\n", "pval = @btime sim_t_test(L=100);" ] }, { "cell_type": "code", "execution_count": 3, "id": "0817695d-7bf4-4ddf-b124-eb8015bb74ee", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n" ], "text/plain": [ "ProfileCanvas.ProfileData(Dict{String, ProfileCanvas.ProfileFrame}(\"count\" => ProfileCanvas.ProfileFrame(\"root\", \"\", \"\", 0, 130, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"#15\", \"task.jl\", \".\\\\task.jl\", 484, 130, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"eventloop\", \"eventloop.jl\", \"D:\\\\.julia\\\\packages\\\\IJulia\\\\AQu2H\\\\src\\\\eventloop.jl\", 8, 130, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"invokelatest\", \"essentials.jl\", \".\\\\essentials.jl\", 726, 130, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"#invokelatest#2\", \"essentials.jl\", \".\\\\essentials.jl\", 729, 130, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"execute_request\", \"execute_request.jl\", \"D:\\\\.julia\\\\packages\\\\IJulia\\\\AQu2H\\\\src\\\\execute_request.jl\", 67, 130, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"softscope_include_string\", \"SoftGlobalScope.jl\", \"D:\\\\.julia\\\\packages\\\\SoftGlobalScope\\\\u4UzH\\\\src\\\\SoftGlobalScope.jl\", 65, 130, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"include_string\", \"loading.jl\", \".\\\\loading.jl\", 1428, 130, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"eval\", \"boot.jl\", \".\\\\boot.jl\", 368, 130, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Tuple{Symbol}\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.SimpleVector\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"DataType\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"UnionAll\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Tuple{Int64}\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"UnknownType\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.CodeInfo\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Vector{UInt8}\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"CorruptType\", \"\", \"\", 0, 5, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Vector{Any}\", \"\", \"\", 0, 3, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Expr\", \"\", \"\", 0, 2, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.Argument\", \"\", \"\", 0, 2, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.ReturnNode\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.LineInfoNode\", \"\", \"\", 0, 2, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Vector{Symbol}\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Vector{Int32}\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"BufferType\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"sim_t_test##kw\", \"In[2]\", \".\\\\In[2]\", 3, 104, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"#sim_t_test#1\", \"In[2]\", \".\\\\In[2]\", 4, 1, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"getindex\", \"array.jl\", \".\\\\array.jl\", 404, 1, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Array\", \"boot.jl\", \".\\\\boot.jl\", 459, 1, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Vector{Float64}\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[])])])]), ProfileCanvas.ProfileFrame(\"#sim_t_test#1\", \"In[2]\", \".\\\\In[2]\", 6, 100, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"rand\", \"genericrand.jl\", \"D:\\\\.julia\\\\packages\\\\Distributions\\\\tFdHM\\\\src\\\\genericrand.jl\", 22, 100, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"rand\", \"genericrand.jl\", \"D:\\\\.julia\\\\packages\\\\Distributions\\\\tFdHM\\\\src\\\\genericrand.jl\", 24, 100, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"rand\", \"genericrand.jl\", \"D:\\\\.julia\\\\packages\\\\Distributions\\\\tFdHM\\\\src\\\\genericrand.jl\", 51, 100, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Array\", \"boot.jl\", \".\\\\boot.jl\", 476, 100, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Array\", \"boot.jl\", \".\\\\boot.jl\", 468, 100, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Array\", \"boot.jl\", \".\\\\boot.jl\", 459, 100, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Vector{Float64}\", \"\", \"\", 0, 100, missing, 0x02, missing, ProfileCanvas.ProfileFrame[])])])])])])])]), ProfileCanvas.ProfileFrame(\"#sim_t_test#1\", \"In[2]\", \".\\\\In[2]\", 11, 3, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"push!\", \"array.jl\", \".\\\\array.jl\", 1058, 3, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"_growend!\", \"array.jl\", \".\\\\array.jl\", 1011, 3, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"BufferType\", \"\", \"\", 0, 3, missing, 0x02, missing, ProfileCanvas.ProfileFrame[])])])])])])])])])])])])])]), \"size\" => ProfileCanvas.ProfileFrame(\"root\", \"\", \"\", 0, 15856, \"16 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"#15\", \"task.jl\", \".\\\\task.jl\", 484, 15856, \"16 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"eventloop\", \"eventloop.jl\", \"D:\\\\.julia\\\\packages\\\\IJulia\\\\AQu2H\\\\src\\\\eventloop.jl\", 8, 15856, \"16 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"invokelatest\", \"essentials.jl\", \".\\\\essentials.jl\", 726, 15856, \"16 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"#invokelatest#2\", \"essentials.jl\", \".\\\\essentials.jl\", 729, 15856, \"16 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"execute_request\", \"execute_request.jl\", \"D:\\\\.julia\\\\packages\\\\IJulia\\\\AQu2H\\\\src\\\\execute_request.jl\", 67, 15856, \"16 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"softscope_include_string\", \"SoftGlobalScope.jl\", \"D:\\\\.julia\\\\packages\\\\SoftGlobalScope\\\\u4UzH\\\\src\\\\SoftGlobalScope.jl\", 65, 15856, \"16 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"include_string\", \"loading.jl\", \".\\\\loading.jl\", 1428, 15856, \"16 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"eval\", \"boot.jl\", \".\\\\boot.jl\", 368, 15856, \"16 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Tuple{Symbol}\", \"\", \"\", 0, 8, \"8 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.SimpleVector\", \"\", \"\", 0, 32, \"32 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"DataType\", \"\", \"\", 0, 96, \"96 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"UnionAll\", \"\", \"\", 0, 112, \"112 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Tuple{Int64}\", \"\", \"\", 0, 120, \"120 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"UnknownType\", \"\", \"\", 0, 136, \"136 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.CodeInfo\", \"\", \"\", 0, 256, \"256 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Vector{UInt8}\", \"\", \"\", 0, 300, \"300 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"CorruptType\", \"\", \"\", 0, 612, \"828 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Vector{Any}\", \"\", \"\", 0, 620, \"1 KB\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Expr\", \"\", \"\", 0, 508, \"612 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.Argument\", \"\", \"\", 0, 508, \"620 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.ReturnNode\", \"\", \"\", 0, 628, \"628 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.LineInfoNode\", \"\", \"\", 0, 908, \"908 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Vector{Symbol}\", \"\", \"\", 0, 1036, \"1 KB\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Vector{Int32}\", \"\", \"\", 0, 1112, \"1 KB\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"BufferType\", \"\", \"\", 0, 1224, \"1 KB\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"sim_t_test##kw\", \"In[2]\", \".\\\\In[2]\", 3, 14632, \"15 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"#sim_t_test#1\", \"In[2]\", \".\\\\In[2]\", 4, 48, \"48 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"getindex\", \"array.jl\", \".\\\\array.jl\", 404, 48, \"48 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Array\", \"boot.jl\", \".\\\\boot.jl\", 459, 48, \"48 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Vector{Float64}\", \"\", \"\", 0, 48, \"48 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[])])])]), ProfileCanvas.ProfileFrame(\"#sim_t_test#1\", \"In[2]\", \".\\\\In[2]\", 6, 12800, \"13 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"rand\", \"genericrand.jl\", \"D:\\\\.julia\\\\packages\\\\Distributions\\\\tFdHM\\\\src\\\\genericrand.jl\", 22, 12800, \"13 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"rand\", \"genericrand.jl\", \"D:\\\\.julia\\\\packages\\\\Distributions\\\\tFdHM\\\\src\\\\genericrand.jl\", 24, 12800, \"13 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"rand\", \"genericrand.jl\", \"D:\\\\.julia\\\\packages\\\\Distributions\\\\tFdHM\\\\src\\\\genericrand.jl\", 51, 12800, \"13 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Array\", \"boot.jl\", \".\\\\boot.jl\", 476, 12800, \"13 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Array\", \"boot.jl\", \".\\\\boot.jl\", 468, 12800, \"13 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Array\", \"boot.jl\", \".\\\\boot.jl\", 459, 12800, \"13 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"Vector{Float64}\", \"\", \"\", 0, 12800, \"13 KB\", 0x02, missing, ProfileCanvas.ProfileFrame[])])])])])])])]), ProfileCanvas.ProfileFrame(\"#sim_t_test#1\", \"In[2]\", \".\\\\In[2]\", 11, 1784, \"2 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"push!\", \"array.jl\", \".\\\\array.jl\", 1058, 1784, \"2 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"_growend!\", \"array.jl\", \".\\\\array.jl\", 1011, 1784, \"2 KB\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"BufferType\", \"\", \"\", 0, 1784, \"2 KB\", 0x02, missing, ProfileCanvas.ProfileFrame[])])])])])])])])])])])])])])), \"Allocation\")" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "@profview_allocs sim_t_test(L=100) sample_rate=1" ] }, { "cell_type": "code", "execution_count": 4, "id": "d3e83516-bbeb-4567-96be-8f13c96f517c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.037631 seconds (45.87 k allocations: 2.538 MiB, 97.36% compilation time)\n", " 0.000053 seconds (2 allocations: 96 bytes)\n", " 0.000054 seconds (2 allocations: 96 bytes)\n", " 28.900 μs (0 allocations: 0 bytes)\n" ] } ], "source": [ "using Distributions\n", "using Random\n", "\n", "function sim_t_test_rev(; dist = Normal(), n = 10, μ = mean(dist), L = 10^5,\n", " pval = Vector{Float64}(undef, L),\n", " tmp = Vector{Float64}(undef, n)\n", " )\n", " for i in 1:L\n", " X = rand!(dist, tmp)\n", " X̄ = mean(X)\n", " S = std(X)\n", " t = √n * (X̄ - μ)/S\n", " pval[i] = 2ccdf(TDist(n-1), abs(t))\n", " end\n", " pval\n", "end\n", "\n", "n = 10\n", "L = 100\n", "pval = Vector{Float64}(undef, L)\n", "tmp = Vector{Float64}(undef, n)\n", "pval = @time sim_t_test_rev(; n, L, pval, tmp)\n", "pval = @time sim_t_test_rev(; n, L, pval, tmp)\n", "pval = @time sim_t_test_rev(; n, L, pval, tmp)\n", "pval = @btime sim_t_test_rev(; n=$n, L=$L, pval=$pval, tmp=$tmp);" ] }, { "cell_type": "code", "execution_count": 5, "id": "58309873-66b9-4f59-9c1a-1568ce94f878", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n" ], "text/plain": [ "ProfileCanvas.ProfileData(Dict{String, ProfileCanvas.ProfileFrame}(\"count\" => ProfileCanvas.ProfileFrame(\"root\", \"\", \"\", 0, 6, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"#15\", \"task.jl\", \".\\\\task.jl\", 484, 6, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"eventloop\", \"eventloop.jl\", \"D:\\\\.julia\\\\packages\\\\IJulia\\\\AQu2H\\\\src\\\\eventloop.jl\", 8, 6, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"invokelatest\", \"essentials.jl\", \".\\\\essentials.jl\", 726, 6, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"#invokelatest#2\", \"essentials.jl\", \".\\\\essentials.jl\", 729, 6, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"execute_request\", \"execute_request.jl\", \"D:\\\\.julia\\\\packages\\\\IJulia\\\\AQu2H\\\\src\\\\execute_request.jl\", 67, 6, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"softscope_include_string\", \"SoftGlobalScope.jl\", \"D:\\\\.julia\\\\packages\\\\SoftGlobalScope\\\\u4UzH\\\\src\\\\SoftGlobalScope.jl\", 65, 6, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"include_string\", \"loading.jl\", \".\\\\loading.jl\", 1428, 6, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"eval\", \"boot.jl\", \".\\\\boot.jl\", 368, 6, missing, 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"NTuple{4, Symbol}\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.SimpleVector\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"DataType\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"UnionAll\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Tuple{Int64, Int64, Vector{Float64}, Vector{Float64}}\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"UnknownType\", \"\", \"\", 0, 1, missing, 0x02, missing, ProfileCanvas.ProfileFrame[])])])])])])])])])]), \"size\" => ProfileCanvas.ProfileFrame(\"root\", \"\", \"\", 0, 216, \"216 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"#15\", \"task.jl\", \".\\\\task.jl\", 484, 216, \"216 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"eventloop\", \"eventloop.jl\", \"D:\\\\.julia\\\\packages\\\\IJulia\\\\AQu2H\\\\src\\\\eventloop.jl\", 8, 216, \"216 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"invokelatest\", \"essentials.jl\", \".\\\\essentials.jl\", 726, 216, \"216 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"#invokelatest#2\", \"essentials.jl\", \".\\\\essentials.jl\", 729, 216, \"216 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"execute_request\", \"execute_request.jl\", \"D:\\\\.julia\\\\packages\\\\IJulia\\\\AQu2H\\\\src\\\\execute_request.jl\", 67, 216, \"216 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"softscope_include_string\", \"SoftGlobalScope.jl\", \"D:\\\\.julia\\\\packages\\\\SoftGlobalScope\\\\u4UzH\\\\src\\\\SoftGlobalScope.jl\", 65, 216, \"216 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"include_string\", \"loading.jl\", \".\\\\loading.jl\", 1428, 216, \"216 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"eval\", \"boot.jl\", \".\\\\boot.jl\", 368, 216, \"216 bytes\", 0x00, missing, ProfileCanvas.ProfileFrame[ProfileCanvas.ProfileFrame(\"NTuple{4, Symbol}\", \"\", \"\", 0, 32, \"32 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Core.SimpleVector\", \"\", \"\", 0, 56, \"56 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"DataType\", \"\", \"\", 0, 120, \"120 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"UnionAll\", \"\", \"\", 0, 136, \"136 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"Tuple{Int64, Int64, Vector{Float64}, Vector{Float64}}\", \"\", \"\", 0, 168, \"168 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[]), ProfileCanvas.ProfileFrame(\"UnknownType\", \"\", \"\", 0, 216, \"216 bytes\", 0x02, missing, ProfileCanvas.ProfileFrame[])])])])])])])])])])), \"Allocation\")" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "@profview_allocs sim_t_test_rev(; n, L, pval, tmp) sample_rate=1" ] }, { "cell_type": "code", "execution_count": 6, "id": "2dcd5959-c654-4dc3-859d-b8b008a99c4c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1 + 2 * sum((sin(x) / x for x = 1:10 ^ 8)): 2.720984 seconds (357.91 k allocations: 18.300 MiB, 3.61% compilation time)\n" ] }, { "data": { "text/plain": [ "3.1415926695599605" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val = @showtime 1 + 2sum(sin(x)/x for x in 1:10^8)\n", "val" ] }, { "cell_type": "code", "execution_count": 7, "id": "3ae03b8c-0cf7-4397-93da-991265d32e68", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pval = Float64[]: 0.000003 seconds (1 allocation: 64 bytes)\n", "\n", "i = 1\n", "X = rand(dist, n): 0.000004 seconds (1 allocation: 144 bytes)\n", "X̄ = mean(X): 0.000000 seconds\n", "S = std(X): 0.000002 seconds\n", "t = (√n * (X̄ - μ)) / S: 0.000000 seconds\n", "p = 2 * ccdf(TDist(n - 1), abs(t)): 0.000015 seconds\n", "push!(pval, p): 0.000001 seconds (1 allocation: 80 bytes)\n", "\n", "i = 2\n", "X = rand(dist, n): 0.000002 seconds (1 allocation: 144 bytes)\n", "X̄ = mean(X): 0.000000 seconds\n", "S = std(X): 0.000001 seconds\n", "t = (√n * (X̄ - μ)) / S: 0.000000 seconds\n", "p = 2 * ccdf(TDist(n - 1), abs(t)): 0.000002 seconds\n", "push!(pval, p): 0.000000 seconds\n", "\n", "i = 3\n", "X = rand(dist, n): 0.000002 seconds (1 allocation: 144 bytes)\n", "X̄ = mean(X): 0.000000 seconds\n", "S = std(X): 0.000000 seconds\n", "t = (√n * (X̄ - μ)) / S: 0.000000 seconds\n", "p = 2 * ccdf(TDist(n - 1), abs(t)): 0.000002 seconds\n", "push!(pval, p): 0.000001 seconds\n", "\n", "i = 4\n", "X = rand(dist, n): 0.000001 seconds (1 allocation: 144 bytes)\n", "X̄ = mean(X): 0.000000 seconds\n", "S = std(X): 0.000000 seconds\n", "t = (√n * (X̄ - μ)) / S: 0.000000 seconds\n", "p = 2 * ccdf(TDist(n - 1), abs(t)): 0.000002 seconds\n", "push!(pval, p): 0.000000 seconds\n", "\n", "i = 5\n", "X = rand(dist, n): 0.000000 seconds (1 allocation: 144 bytes)\n", "X̄ = mean(X): 0.000000 seconds\n", "S = std(X): 0.000000 seconds\n", "t = (√n * (X̄ - μ)) / S: 0.000000 seconds\n", "p = 2 * ccdf(TDist(n - 1), abs(t)): 0.000001 seconds\n", "push!(pval, p): 0.000000 seconds\n", "\n", "i = 6\n", "X = rand(dist, n): 0.000001 seconds (1 allocation: 144 bytes)\n", "X̄ = mean(X): 0.000000 seconds\n", "S = std(X): 0.000000 seconds\n", "t = (√n * (X̄ - μ)) / S: 0.000000 seconds\n", "p = 2 * ccdf(TDist(n - 1), abs(t)): 0.000009 seconds\n", "push!(pval, p): 0.000002 seconds\n", "\n", "i = 7\n", "X = rand(dist, n): 0.000001 seconds (1 allocation: 144 bytes)\n", "X̄ = mean(X): 0.000000 seconds\n", "S = std(X): 0.000000 seconds\n", "t = (√n * (X̄ - μ)) / S: 0.000000 seconds\n", "p = 2 * ccdf(TDist(n - 1), abs(t)): 0.000001 seconds\n", "push!(pval, p): 0.000000 seconds\n", "\n", "i = 8\n", "X = rand(dist, n): 0.000001 seconds (1 allocation: 144 bytes)\n", "X̄ = mean(X): 0.000000 seconds\n", "S = std(X): 0.000000 seconds\n", "t = (√n * (X̄ - μ)) / S: 0.000000 seconds\n", "p = 2 * ccdf(TDist(n - 1), abs(t)): 0.000004 seconds\n", "push!(pval, p): 0.000001 seconds\n", "\n", "i = 9\n", "X = rand(dist, n): 0.000007 seconds (1 allocation: 144 bytes)\n", "X̄ = mean(X): 0.000002 seconds\n", "S = std(X): 0.000002 seconds\n", "t = (√n * (X̄ - μ)) / S: 0.000001 seconds\n", "p = 2 * ccdf(TDist(n - 1), abs(t)): 0.000010 seconds\n", "push!(pval, p): 0.000001 seconds (1 allocation: 336 bytes)\n", "\n", "i = 10\n", "X = rand(dist, n): 0.000002 seconds (1 allocation: 144 bytes)\n", "X̄ = mean(X): 0.000000 seconds\n", "S = std(X): 0.000000 seconds\n", "t = (√n * (X̄ - μ)) / S: 0.000000 seconds\n", "p = 2 * ccdf(TDist(n - 1), abs(t)): 0.000004 seconds\n", "push!(pval, p): 0.000001 seconds\n", "\n", "pval: 0.000000 seconds\n" ] } ], "source": [ "function sim_t_test_showtime(; dist = Normal(), n = 10, μ = mean(dist), L = 10)\n", " @showtime pval = Float64[]\n", " println()\n", " for i in 1:L\n", " @show i\n", " @showtime X = rand(dist, n)\n", " @showtime X̄ = mean(X)\n", " @showtime S = std(X)\n", " @showtime t = √n * (X̄ - μ)/S\n", " @showtime p = 2ccdf(TDist(n-1), abs(t))\n", " @showtime push!(pval, p)\n", " println()\n", " end\n", " @showtime pval\n", "end\n", "\n", "sim_t_test_showtime();" ] }, { "cell_type": "code", "execution_count": null, "id": "fa37dbd5-e778-4b43-9abe-3ba42cd7d575", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "encoding": "# -*- coding: utf-8 -*-", "formats": "ipynb,jl:hydrogen" }, "kernelspec": { "display_name": "Julia 1.8.0", "language": "julia", "name": "julia-1.8" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.8.0" } }, "nbformat": 4, "nbformat_minor": 5 }