-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler_stresstest.jl
40 lines (31 loc) · 1.3 KB
/
compiler_stresstest.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module TortureTest
# Scalability parameters - set here to roughly match the real world usecase
# though that use case does more work.
const NFIELDS = 888
const NSET = 387
const NREPS = 40
using Random
using Base.Meta
struct Maybe{T}
x::T
is_missing::Bool
end
Base.convert(::Type{Maybe{T}}, x::Maybe{T}) where {T} = x
Base.convert(::Type{Maybe{T}}, x::T) where {T} = Maybe{T}(x, true)
Base.convert(::Type{Maybe{T}}, x) where {T} = Maybe{T}(convert(T, x), true)
Base.eltype(::Type{Maybe{T}}) where {T} = T
Maybe(x::T) where {T} = Maybe(x, false)
@eval struct TestCase
$([:($(Symbol("x$i"))::Maybe{$(rand(Bool) ? Float64 : Int64)}) for i = 1:NFIELDS]...)
end
@eval TestCase($(Expr(:parameters, [Expr(:kw, Symbol("x$i"), :(Maybe(convert(eltype(fieldtype(TestCase, $(quot(Symbol("x$i"))))), $(rand(Bool) ? Float64(i) : i))))) for i = 1:NFIELDS]...))) =
TestCase($([Symbol("x$i") for i = 1:NFIELDS]...))
@eval function run_test1(x)
$([:(TestCase(;$([:($(Symbol("x$i")) = $(rand() < 0.05 ? (:x) : rand(Bool) ? Float64(i) : i)) for i = randperm(NFIELDS)[1:NSET]]...))) for _ = 1:NREPS]...)
end
@eval function run_test2(x)
$([:(TestCase(;$([:($(Symbol("x$i")) = $(rand(Bool) ? Float64(i) : i)) for i = randperm(NFIELDS)[1:NSET]]...))) for _ = 1:NREPS]...)
end
end
using Cthulhu
TortureTest.run_test1(1)