This repository was archived by the owner on Dec 16, 2022. It is now read-only.
forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathperfutil.jl
103 lines (91 loc) · 3.22 KB
/
perfutil.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const ntrials = 5
print_output = isempty(ARGS)
codespeed = length(ARGS) > 0 && ARGS[1] == "codespeed"
if codespeed
using JSON
using HTTPClient.HTTPC
# Ensure that we've got the environment variables we want:
if !haskey(ENV, "JULIA_FLAVOR")
error( "You must provide the JULIA_FLAVOR environment variable identifying this julia build!" )
end
# Setup codespeed data dict for submissions to codespeed's JSON endpoint. These parameters
# are constant across all benchmarks, so we'll just let them sit here for now
csdata = Dict()
csdata["commitid"] = Base.GIT_VERSION_INFO.commit
csdata["project"] = "Julia"
csdata["branch"] = Base.GIT_VERSION_INFO.branch
csdata["executable"] = ENV["JULIA_FLAVOR"]
csdata["environment"] = chomp(readall(`hostname`))
csdata["result_date"] = join( split(Base.GIT_VERSION_INFO.date_string)[1:2], " " ) #Cut the timezone out
end
# Takes in the raw array of values in vals, along with the benchmark name, description, unit and whether less is better
function submit_to_codespeed(vals,name,desc,unit,test_group,lessisbetter=true)
# Points to the server
codespeed_host = "julia-codespeed.csail.mit.edu"
csdata["benchmark"] = name
csdata["description"] = desc
csdata["result_value"] = mean(vals)
csdata["std_dev"] = std(vals)
csdata["min"] = minimum(vals)
csdata["max"] = maximum(vals)
csdata["units"] = unit
csdata["units_title"] = test_group
csdata["lessisbetter"] = lessisbetter
println( "$name: $(mean(vals))" )
ret = post( "http://$codespeed_host/result/add/json/", {"json" => json([csdata])} )
if ret.http_code != 200 && ret.http_code != 202
error("Error submitting $name [HTTP code $(ret.http_code)], dumping headers and text: $(ret.headers)\n$(bytestring(ret.body))\n\n")
return false
end
return true
end
macro output_timings(t,name,desc,group)
quote
# If we weren't given anything for the test group, infer off of file path!
test_group = length($group) == 0 ? basename(dirname(Base.source_path())) : $group[1]
if codespeed
submit_to_codespeed( $t, $name, $desc, "seconds", test_group )
elseif print_output
@printf "julia,%s,%f,%f,%f,%f\n" $name minimum($t) maximum($t) mean($t) std($t)
end
gc()
end
end
macro timeit(ex,name,desc,group...)
quote
t = zeros(ntrials)
for i=0:ntrials
e = 1000*(@elapsed $(esc(ex)))
if i > 0
# warm up on first iteration
t[i] = e
end
end
@output_timings t $name $desc $group
end
end
macro timeit1(ex,name,desc,group...)
quote
t = 0.0
for i=0:1
t = 1000*(@elapsed $(esc(ex)))
end
@output_timings [t] $name $desc $group
end
end
macro timeit_init(ex,init,name,desc,group...)
quote
t = zeros(ntrials)
for i=0:ntrials
$(esc(init))
e = 1000*(@elapsed $(esc(ex)))
if i > 0
# warm up on first iteration
t[i] = e
end
end
@output_timings t $name $desc $group
end
end
# seed rng for more consistent timings
srand(1776)