Skip to content

Commit

Permalink
Convert GLM example
Browse files Browse the repository at this point in the history
  • Loading branch information
VarLad committed Dec 23, 2023
1 parent e30f437 commit a28de02
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
31 changes: 11 additions & 20 deletions perf/GLM/allocs.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
using PerfChecker
using Test

using GLM
using Random
using StatsModels

@testset "GLM.jl" begin
title = "Basic GLM computation"
dependencies = [GLM]
targets = [GLM]

function alloc()
j = @prep CheckerOptions(1, "/var/home/varlad/PerfChecker.jl/perf/GLM", ["GLM"]) begin
using GLM, Random, StatsModels
@check begin
n = 2_500_000
rng = Random.MersenneTwister(1234321)
tbl = (
x1 = randn(rng, n),
x2 = Random.randexp(rng, n),
ss = rand(rng, string.(50:99), n),
y = zeros(n),
)
f = @formula(y ~ 1 + x1 + x2 + ss)
x1=randn(rng, n),
x2=Random.randexp(rng, n),
ss=rand(rng, string.(50:99), n),
y=zeros(n),
)
f = @eval @formula(y ~ 1 + x1 + x2 + ss)
f = apply_schema(f, schema(f, tbl))
resp, pred = modelcols(f, tbl)
B = randn(rng, size(pred, 2))
B[1] = 0.5
logistic(x::Real) = inv(1 + exp(-x))
resp .= rand(rng, n) .< logistic.(pred * B)
glm(pred, resp, Bernoulli())
return nothing
end

alloc_check(title, dependencies, targets, alloc, alloc; path=@__DIR__)
end

println(j)
17 changes: 11 additions & 6 deletions src/allocations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ macro prep(options, block)
import Pkg; Pkg.instantiate();
import Profile;
macro check(repeat, block)
quote
repeat && $(esc(block))
Profile.clear_malloc_data()
$(esc(block))
end
repeat && block
Profile.clear_malloc_data()
block
end
#=
macro check(block)
quote
$(esc(block))
Profile.clear_malloc_data()
$(esc(block))
end
end
=#
macro check(block)
block
Profile.clear_malloc_data()
block
end
$block
targets = eval(Meta.parse("[" * (typeof($targets) == String ? $targets : join($targets, ", ")) * "]"))
targets = eval(Meta.parse("[" * (typeof($targets) == String ? $targets : join($targets, ", ")) * "]")); @warn targets
return map(dirname pathof eval, targets)
end).args...))

Expand Down

0 comments on commit a28de02

Please sign in to comment.