Skip to content

Commit 5d3934c

Browse files
authored
Merge pull request #63 from skleinbo/belapsed
Use @belapsed for performance measurements
2 parents 66f23a3 + 57efbad commit 5d3934c

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
1919
UnivariateFiniteDisplayExt = "UnicodePlots"
2020

2121
[compat]
22+
BenchmarkTools = "1.3.2"
2223
CategoricalArrays = "0.9, 0.10"
2324
Distributions = "0.25"
2425
Missings = "0.4, 1"
@@ -28,11 +29,12 @@ UnicodePlots = "2, 3"
2829
julia = "1.6"
2930

3031
[extras]
32+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
33+
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
3134
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
3235
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
3336
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
34-
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
3537
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
3638

3739
[targets]
38-
test = ["FillArrays", "Random", "StableRNGs", "Test", "UnicodePlots"]
40+
test = ["BenchmarkTools", "FillArrays", "Random", "StableRNGs", "Test", "UnicodePlots"]

test/arithmetic.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
module TestArithmetic
22

33
using Test
4+
import BenchmarkTools: @belapsed
45
using CategoricalDistributions
56
using StableRNGs
67
rng = StableRNG(123)
78

9+
macro belapsed1(ex)
10+
:(@belapsed $ex seconds=1 evals=1)
11+
end
12+
813
L = ["yes", "no"]
914
d1 = UnivariateFinite(L, rand(rng, 2), pool=missing)
1015
d2 = UnivariateFinite(L, rand(rng, 2), pool=missing)
@@ -46,27 +51,27 @@ fast = UnivariateFinite(L, P, pool=missing);
4651

4752
@testset "performant arithmetic for UnivariateFiniteArray" begin
4853
@test pdf(slow + slow, L) == pdf(fast + fast, L)
49-
t_slow = @elapsed @eval slow + slow
50-
t_fast = @elapsed @eval fast + fast
54+
t_slow = @belapsed1 $slow + $slow
55+
t_fast = @belapsed1 $fast + $fast
5156
@test t_slow/t_fast > 10
5257

5358
@test pdf(slow - slow, L) == pdf(fast - fast, L)
54-
t_slow = @elapsed @eval slow - slow
55-
t_fast = @elapsed @eval fast - fast
59+
t_slow = @belapsed1 $slow - $slow
60+
t_fast = @belapsed1 $fast - $fast
5661
@test t_slow/t_fast > 10
5762

5863
@test pdf(42*slow, L) == pdf(42*fast, L)
5964
@test pdf(slow*42, L) == pdf(fast*42, L)
60-
t_slow = @elapsed @eval 42*slow
61-
t_fast = @elapsed @eval 42*fast
65+
t_slow = @belapsed1 42*$slow
66+
t_fast = @belapsed1 42*$fast
6267
@test t_slow/t_fast > 10
63-
t_slow = @elapsed @eval slow*42
64-
t_fast = @elapsed @eval fast*42
68+
t_slow = @belapsed1 $slow*42
69+
t_fast = @belapsed1 $fast*42
6570
@test t_slow/t_fast > 10
6671

6772
@test pdf(slow/42, L) == pdf(fast/42, L)
68-
t_slow = @elapsed @eval slow/42
69-
t_fast = @elapsed @eval fast/42
73+
t_slow = @belapsed1 $slow/42
74+
t_fast = @belapsed1 $fast/42
7075
@test t_slow/t_fast > 10
7176
end
7277

0 commit comments

Comments
 (0)