Skip to content

Commit 5028738

Browse files
authored
feat: precompilation with PrecompileTools (#167)
* feat: add precompilation with PrecompileTools * refactor: beef up precompilation * refactor: beef up precompilation
1 parent 3386209 commit 5028738

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "1.5.1"
55

66
[deps]
77
DispatchDoctor = "8d63f2c5-f18a-4cf2-ba9d-b3f60fc568c8"
8+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
89
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"
910
Tricks = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"
1011

@@ -24,6 +25,7 @@ DynamicQuantitiesUnitfulExt = "Unitful"
2425
DispatchDoctor = "0.4"
2526
LinearAlgebra = "1"
2627
Measurements = "2"
28+
PrecompileTools = "1"
2729
ScientificTypes = "3"
2830
TestItems = "0.1, 1"
2931
Tricks = "0.1.9"

src/DynamicQuantities.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ let _units_import_expr = :(using .Units: m, g)
5252
eval(_units_import_expr)
5353
end
5454

55+
# Include precompilation directives
56+
include("precompile.jl")
57+
5558
end

src/precompile.jl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import PrecompileTools
2+
3+
PrecompileTools.@setup_workload begin
4+
PrecompileTools.@compile_workload begin
5+
q1 = u"m"
6+
q1_s = us"m"
7+
q2 = u"kg"
8+
q2_s = us"kg"
9+
q3 = u"m/s"
10+
q3_s = us"m/s"
11+
12+
# Basic operations
13+
q1 + q1
14+
q1_s + q1_s
15+
q1 + q1_s
16+
q1_s + q1
17+
18+
q1 - q1
19+
q1_s - q1_s
20+
q1 - q1_s
21+
q1_s - q1
22+
23+
q1 * 2.0
24+
q1_s * 2.0
25+
2.0 * q1
26+
q1_s * 2.0
27+
28+
q1 / 2.0
29+
q1_s / 2.0
30+
31+
2.0 / q1
32+
2.0 / q1_s
33+
34+
q1 * q2
35+
q1_s * q2_s
36+
q1 * q2_s
37+
q1_s * q2
38+
39+
q1 / q3
40+
q1_s / q3_s
41+
q1 / q3_s
42+
q1_s / q3
43+
44+
# Power operations
45+
q3^2
46+
q3_s^2
47+
q3^2.0
48+
q3_s^2.0
49+
inv(q3)
50+
inv(q3_s)
51+
52+
# Conversion/display
53+
string(q3)
54+
string(q3_s)
55+
show(devnull, MIME"text/plain"(), q1)
56+
show(devnull, MIME"text/plain"(), q1_s)
57+
print(devnull, q1)
58+
print(devnull, q1_s)
59+
60+
# Comparison operations
61+
q1 == q1
62+
q1_s == q1_s
63+
q1 == q1_s
64+
q1_s == q1
65+
66+
# Array operations
67+
x = fill(q1, 10)
68+
y = fill(q1_s, 10)
69+
print(devnull, x)
70+
print(devnull, y)
71+
end
72+
end

0 commit comments

Comments
 (0)