Skip to content

Commit d97a030

Browse files
authored
Merge pull request #31 from johnfgibson/compat-0.6-1.0
add @compat calls for 0.6/0.7/1.0 compatibility
2 parents 2d46acf + 0421fc4 commit d97a030

File tree

4 files changed

+57
-33
lines changed

4 files changed

+57
-33
lines changed

bin/table.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# This script generates the table published at https://julialang.org/benchmarks/
44
# (file _includes/benchmarks.html in the JuliaLang/julialang.github.com repository)
55

6-
using Statistics
6+
using Compat
7+
import Compat.Statistics
8+
import Compat.Printf
79

810
const benchmark_order = [
911
"iteration_pi_sum",
@@ -53,10 +55,10 @@ function lang_by(lang::String)
5355
# C is placed at the start of the list
5456
lang == "c" ? -Inf :
5557
# Julia is sorted immediately after C
56-
lang == "julia" ? -realmax() :
58+
@compat lang == "julia" ? -floatmax() :
5759
# The rest of the languages are sorted by the geometric mean of their benchmark values
5860
# See https://en.wikipedia.org/wiki/Geometric_mean#Relationship_with_logarithms for details
59-
exp(mean(log.(collect(values(benchmarks[lang])))))
61+
@compat exp(Statistics.mean(log.(collect(values(benchmarks[lang])))))
6062
end
6163

6264
const language_order = sort!(collect(keys(benchmarks)), by=lang_by)
@@ -94,15 +96,13 @@ print("""
9496
<tbody>
9597
""")
9698

97-
using Printf
98-
9999
for benchmark in benchmark_order
100100
println(" <tr><th>$benchmark</th>")
101101
c_time = benchmarks["c"][benchmark]
102102
for lang in language_order
103103
rel_time = "n/a"
104104
if haskey(benchmarks[lang], benchmark)
105-
rel_time = @sprintf "%.2f" benchmarks[lang][benchmark]/c_time
105+
@compat rel_time = Printf.@sprintf "%.2f" benchmarks[lang][benchmark]/c_time
106106
end
107107
println(" <td class=\"data\">$rel_time</td>")
108108
end

bin/versions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ echo -n java,
1313
java -version 2>&1 |grep "version" | cut -f3 -d " " | cut -c 2-9
1414

1515
echo -n "javascript,V8 "
16-
nodejs -e "console.log(process.versions.v8)"
16+
node8 -e "console.log(process.versions.v8)"
1717

1818
echo -n "julia,"
1919
$JULIAHOME/usr/bin/julia -v | cut -f3 -d" "
@@ -29,7 +29,7 @@ echo -n "matlab,R"
2929
matlab -nodisplay -nojvm -nosplash -r "version -release, quit" | tail -n3 | head -n1 | cut -f5 -d" " | sed "s/'//g"
3030

3131
echo -n "octave,"
32-
octave -v | grep version | cut -f4 -d" "
32+
octave-cli -v | grep version | cut -f4 -d" "
3333

3434
echo -n "python,"
3535
python3 -V 2>&1 | cut -f2 -d" "

perf.jl

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
# This file was formerly a part of Julia. License is MIT: https://julialang.org/license
22

3-
using LinearAlgebra
4-
using Test
5-
using Printf
3+
using Compat
4+
5+
import Compat.LinearAlgebra
6+
import Compat.Test
7+
import Compat.Printf
8+
import Compat.Statistics
9+
import Compat.Sys
610

711
include("./perfutil.jl")
812

913
## recursive fib ##
1014

1115
fib(n) = n < 2 ? n : fib(n-1) + fib(n-2)
1216

13-
@test fib(20) == 6765
17+
@compat Test.@test fib(20) == 6765
1418
@timeit fib(20) "recursion_fibonacci" "Recursive fibonacci"
1519

1620
## parse integer ##
@@ -19,8 +23,13 @@ function parseintperf(t)
1923
local n, m
2024
for i=1:t
2125
n = rand(UInt32)
22-
s = string(n, base = 16)
23-
m = UInt32(parse(Int64,s, base = 16))
26+
@static if VERSION >= v"0.7.0-DEV.4446"
27+
s = string(n, base = 16)
28+
m = UInt32(parse(Int64, s, base = 16))
29+
else
30+
s = hex(n)
31+
m = UInt32(parse(Int64, s, 16))
32+
end
2433
@assert m == n
2534
end
2635
return n
@@ -30,12 +39,12 @@ end
3039

3140
## array constructors ##
3241

33-
@test all(fill(1.,200,200) .== 1)
42+
@compat Test.@test all(fill(1.,200,200) .== 1)
3443

3544
## matmul and transpose ##
3645

3746
A = fill(1.,200,200)
38-
@test all(A*A' .== 200)
47+
@compat Test.@test all(A*A' .== 200)
3948
# @timeit A*A' "AtA" "description"
4049

4150
## mandelbrot set: complex arithmetic and comprehensions ##
@@ -57,7 +66,7 @@ function mandel(z)
5766
end
5867

5968
mandelperf() = [ mandel(complex(r,i)) for i=-1.:.1:1., r=-2.0:.1:0.5 ]
60-
@test sum(mandelperf()) == 14791
69+
@compat Test.@test sum(mandelperf()) == 14791
6170
@timeit mandelperf() "userfunc_mandelbrot" "Calculation of mandelbrot set"
6271

6372
## numeric vector sort ##
@@ -81,7 +90,7 @@ function qsort!(a,lo,hi)
8190
end
8291

8392
sortperf(n) = qsort!(rand(n), 1, n)
84-
@test issorted(sortperf(5000))
93+
@compat Test.@test issorted(sortperf(5000))
8594
@timeit sortperf(5000) "recursion_quicksort" "Sorting of random numbers using quicksort"
8695

8796
## slow pi series ##
@@ -97,7 +106,7 @@ function pisum()
97106
sum
98107
end
99108

100-
@test abs(pisum()-1.644834071848065) < 1e-12
109+
@compat Test.@test abs(pisum()-1.644834071848065) < 1e-12
101110
@timeit pisum() "iteration_pi_sum" "Summation of a power series"
102111

103112
## slow pi series, vectorized ##
@@ -127,14 +136,19 @@ function randmatstat(t)
127136
d = randn(n,n)
128137
P = [a b c d]
129138
Q = [a b; c d]
130-
v[i] = tr((P'*P)^4)
131-
w[i] = tr((Q'*Q)^4)
139+
@static if VERSION >= v"0.7.0"
140+
v[i] = LinearAlgebra.tr((P'*P)^4)
141+
w[i] = LinearAlgebra.tr((Q'*Q)^4)
142+
else
143+
v[i] = trace((P'*P)^4)
144+
w[i] = trace((Q'*Q)^4)
145+
end
132146
end
133-
return (std(v)/mean(v), std(w)/mean(w))
147+
@compat return (Statistics.std(v)/Statistics.mean(v), Statistics.std(w)/Statistics.mean(w))
134148
end
135149

136150
(s1, s2) = randmatstat(1000)
137-
@test 0.5 < s1 < 1.0 && 0.5 < s2 < 1.0
151+
@compat Test.@test 0.5 < s1 < 1.0 && 0.5 < s2 < 1.0
138152
@timeit randmatstat(1000) "matrix_statistics" "Statistics on a random matrix"
139153

140154
## largish random number gen & matmul ##
@@ -143,11 +157,11 @@ end
143157

144158
## printfd ##
145159

146-
if Sys.isunix()
160+
@compat if Sys.isunix()
147161
function printfd(n)
148162
open("/dev/null", "w") do io
149163
for i = 1:n
150-
@printf(io, "%d %d\n", i, i + 1)
164+
@compat Printf.@printf(io, "%d %d\n", i, i + 1)
151165
end
152166
end
153167
end

perfutil.jl

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# This file was formerly a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Printf, Random, Statistics
3+
using Compat
4+
import Compat.Printf
5+
import Compat.Random
6+
import Compat.Statistics
7+
import Compat.Sys
48

59
const mintrials = 5
610
const mintime = 2000.0
@@ -34,15 +38,15 @@ function submit_to_codespeed(vals,name,desc,unit,test_group,lessisbetter=true)
3438

3539
csdata["benchmark"] = name
3640
csdata["description"] = desc
37-
csdata["result_value"] = mean(vals)
38-
csdata["std_dev"] = std(vals)
41+
@compat csdata["result_value"] = Statistics.mean(vals)
42+
@compat csdata["std_dev"] = Statistics.std(vals)
3943
csdata["min"] = minimum(vals)
4044
csdata["max"] = maximum(vals)
4145
csdata["units"] = unit
4246
csdata["units_title"] = test_group
4347
csdata["lessisbetter"] = lessisbetter
4448

45-
println( "$name: $(mean(vals))" )
49+
@compat println( "$name: $(Statistics.mean(vals))" )
4650
ret = post( "http://$codespeed_host/result/add/json/", Dict("json" => json([csdata])) )
4751
println( json([csdata]) )
4852
if ret.http_code != 200 && ret.http_code != 202
@@ -63,7 +67,7 @@ macro output_timings(t,name,desc,group)
6367
if codespeed
6468
submit_to_codespeed( $t, $name, $desc, "seconds", test_group )
6569
elseif print_output
66-
@printf "julia,%s,%f,%f,%f,%f\n" $name minimum($t) maximum($t) mean($t) std($t)
70+
@compat Printf.@printf "julia,%s,%f,%f,%f,%f\n" $name minimum($t) maximum($t) Statistics.mean($t) Statistics.std($t)
6771
end
6872
GC.gc()
6973
end
@@ -106,17 +110,23 @@ end
106110

107111
function maxrss(name)
108112
# FIXME: call uv_getrusage instead here
109-
@static if Sys.islinux()
113+
@compat @static if (Sys.islinux())
110114
rus = Vector{Int64}(uninitialized, div(144,8))
111115
fill!(rus, 0x0)
112116
res = ccall(:getrusage, Int32, (Int32, Ptr{Cvoid}), 0, rus)
113117
if res == 0
114118
mx = rus[5]/1024
115-
@printf "julia,%s.mem,%f,%f,%f,%f\n" name mx mx mx 0
119+
@compat Printf.@printf "julia,%s.mem,%f,%f,%f,%f\n" name mx mx mx 0
116120
end
117121
end
118122
end
119123

120124

121125
# seed rng for more consistent timings
122-
srand(1776)
126+
if VERSION >= v"0.7.0"
127+
Random.seed!(1776)
128+
else
129+
srand(1776)
130+
end
131+
132+
#@compat Random.seed!(1776)

0 commit comments

Comments
 (0)