File tree Expand file tree Collapse file tree 4 files changed +64
-3
lines changed Expand file tree Collapse file tree 4 files changed +64
-3
lines changed Original file line number Diff line number Diff line change 1
1
name = " BenchmarkTools"
2
2
uuid = " 6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3
- version = " 1.1.4 "
3
+ version = " 1.2.0 "
4
4
5
5
[deps ]
6
6
JSON = " 682c06a0-de6a-54ab-a142-c8b1cf79cde6"
7
7
Logging = " 56ddb016-857b-54e1-b83d-db4d58db5568"
8
8
Printf = " de0858da-6303-5e67-8744-51eddeeeb8d7"
9
+ Profile = " 9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
9
10
Statistics = " 10745b16-79ce-11e8-11f9-7d13ad32a3b2"
10
11
UUIDs = " cf7118a7-6976-5b1a-9a39-7adc72f591a4"
11
12
12
13
[compat ]
13
- julia = " 1"
14
14
JSON = " 0.18, 0.19, 0.20, 0.21"
15
+ julia = " 1"
15
16
16
17
[extras ]
17
18
Statistics = " 10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ using Logging: @logmsg, LogLevel
7
7
using Statistics
8
8
using UUIDs: uuid4
9
9
using Printf
10
+ using Profile
10
11
11
12
12
13
const BENCHMARKTOOLS_VERSION = v " 1.0.0"
@@ -68,7 +69,8 @@ export tune!,
68
69
@benchmark ,
69
70
@benchmarkable ,
70
71
@belapsed ,
71
- @btime
72
+ @btime ,
73
+ @bprofile
72
74
73
75
# ################
74
76
# Serialization #
Original file line number Diff line number Diff line change @@ -575,3 +575,30 @@ macro btime(args...)
575
575
$ result
576
576
end )
577
577
end
578
+
579
+ """
580
+ @bprofile expression [other parameters...]
581
+
582
+ Run `@benchmark` while profiling. This is similar to
583
+
584
+ @profile @benchmark expression [other parameters...]
585
+
586
+ but the profiling is applied only to the main
587
+ execution (after compilation and tuning).
588
+ The profile buffer is cleared prior to execution.
589
+
590
+ View the profile results with `Profile.print(...)`.
591
+ See the profiling section of the Julia manual for more
592
+ information.
593
+ """
594
+ macro bprofile (args... )
595
+ _, params = prunekwargs (args... )
596
+ tmp = gensym ()
597
+ return esc (quote
598
+ local $ tmp = $ BenchmarkTools. @benchmarkable $ (args... )
599
+ $ BenchmarkTools. warmup ($ tmp)
600
+ $ (hasevals (params) ? :() : :($ BenchmarkTools. tune! ($ tmp)))
601
+ $ BenchmarkTools. Profile. clear ()
602
+ $ BenchmarkTools. @profile $ BenchmarkTools. run ($ tmp)
603
+ end )
604
+ end
Original file line number Diff line number Diff line change 1
1
module ExecutionTests
2
2
3
3
using BenchmarkTools
4
+ using Profile
4
5
using Test
5
6
6
7
seteq (a, b) = length (a) == length (b) == length (intersect (a, b))
@@ -134,6 +135,36 @@ tune!(b)
134
135
# test kwargs separated by `,`
135
136
@benchmark (output= sin (x), setup= (x= 1.0 ; output= 0.0 ), teardown= (@test output == sin (x)))
136
137
138
+ # ############
139
+ # @bprofile #
140
+ # ############
141
+
142
+ function likegcd (a:: T , b:: T ) where T<: Base.BitInteger
143
+ za = trailing_zeros (a)
144
+ zb = trailing_zeros (b)
145
+ k = min (za, zb)
146
+ u = unsigned (abs (a >> za))
147
+ v = unsigned (abs (b >> zb))
148
+ while u != v
149
+ if u > v
150
+ u, v = v, u
151
+ end
152
+ v -= u
153
+ v >>= trailing_zeros (v)
154
+ end
155
+ r = u << k
156
+ return r % T
157
+ end
158
+
159
+ b = @bprofile likegcd (x, y) setup= (x = rand (2 : 200 ); y = rand (2 : 200 ))
160
+ @test isa (b, BenchmarkTools. Trial)
161
+ io = IOBuffer ()
162
+ Profile. print (IOContext (io, :displaysize => (24 ,200 )))
163
+ str = String (take! (io))
164
+ @test occursin (r" BenchmarkTools(\. jl)?/src/execution\. jl:\d +; _run" , str)
165
+ @test ! occursin (r" BenchmarkTools(\. jl)?/src/execution\. jl:\d +; warmup" , str)
166
+ @test ! occursin (r" BenchmarkTools(\. jl)?/src/execution\. jl:\d +; tune!" , str)
167
+
137
168
# #######
138
169
# misc #
139
170
# #######
You can’t perform that action at this time.
0 commit comments