Skip to content

Commit a33790f

Browse files
Reduce GC usage in example (#692)
* Reduce GC usage * Silence 1.14 warning
1 parent 6114791 commit a33790f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Printf = "1"
5353
Random = "1"
5454
Random123 = "1.7.1"
5555
RandomNumbers = "1.6.0"
56-
SHA = "0.7"
56+
SHA = "0.7, 1"
5757
ScopedValues = "1.3.0"
5858
SpecialFunctions = "2"
5959
StaticArrays = "1"

examples/flopscomp.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function anepeakflops(; kwargs...)
106106
return res
107107
end
108108

109-
function compare(Ns, Fs, inT, outT=inT; n_batch=1, ntrials)
109+
function compare(Ns, Fs, inT, outT=inT; n_batch=1, ntrials, verbose=true)
110110
results = Dict()
111111

112112
newFs = if (outT == Float16 || (outT == Float32 && inT == Float16))
@@ -125,12 +125,12 @@ function compare(Ns, Fs, inT, outT=inT; n_batch=1, ntrials)
125125
verify = (n < maxintfloat(outT) && (inT != Float16 || (n < maxintfloat(inT))))
126126
n_str = "$n: "
127127
for (f, info_str) in newFs
128-
print(prefixstr, n_str, info_str)
128+
verbose && print(prefixstr, n_str, info_str)
129129
push!(results[info_str], f(; inT, outT, n, n_batch, ntrials, verify))
130-
GC.gc()
130+
GC.gc(false)
131131
end
132132
end
133-
print("\33[2K\r")
133+
verbose && print("\33[2K\r")
134134
end
135135
return results
136136
end
@@ -144,10 +144,10 @@ DEFAULT_FS = [
144144
# (cpupeakflops, "CPU (AppleAccelerate)"), # Uncomment to test CPU performance
145145
]
146146

147-
function runcomparison(; Ns=DEFAULT_NS, Fs=DEFAULT_FS, n_batch=1, ntrials=5)
147+
function runcomparison(; Ns=DEFAULT_NS, Fs=DEFAULT_FS, n_batch=1, ntrials=5, verbose=true)
148148
res = Dict()
149149
for (inT, outT) in Ts
150-
res[(inT,outT)] = (n_batch, Ns, compare(Ns, Fs, inT, outT; n_batch, ntrials))
150+
res[(inT,outT)] = (n_batch, Ns, compare(Ns, Fs, inT, outT; n_batch, ntrials, verbose))
151151
end
152152
return res
153153
end
@@ -190,7 +190,7 @@ function plot_results(res, Fs=DEFAULT_FS; outpath=nothing, outtype="svg", plt_ti
190190
end
191191

192192
if testing
193-
runcomparison(Ns=[50, 64, 100, 128, 250, 256, 500, 512])
193+
runcomparison(;Ns=[50, 64, 100, 128, 250, 256, 500, 512], verbose=false)
194194
elseif abspath(PROGRAM_FILE) == @__FILE__
195195
res = runcomparison()
196196
plot_results(res; outpath=".")

0 commit comments

Comments
 (0)