Skip to content

Commit

Permalink
Merge pull request #47 from tk3369/tk/migrate0.7
Browse files Browse the repository at this point in the history
Julia 0.7 support
  • Loading branch information
tk3369 authored Jul 2, 2018
2 parents 57bfdcc + 56c7dc2 commit 0750500
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 21 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ os:
- osx
julia:
- 0.6
- 0.7
- nightly
notifications:
email: false
Expand Down
9 changes: 0 additions & 9 deletions deps/build.jl

This file was deleted.

11 changes: 8 additions & 3 deletions src/CIDict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ Base.haskey(d::CIDict, s::String) = haskey(d.dct, lcase(s))
Base.keys(d::CIDict) = keys(d.dct)
Base.values(d::CIDict) = values(d.dct)

Base.start(d::CIDict) = start(d.dct)
Base.next(d::CIDict, i::Int) = next(d.dct, i)
Base.done(d::CIDict, i::Int) = done(d.dct, i)
@static if VERSION.minor < 7
Base.start(d::CIDict) = start(d.dct)
Base.next(d::CIDict, i::Int) = next(d.dct, i)
Base.done(d::CIDict, i::Int) = done(d.dct, i)
else
Base.iterate(d::CIDict) = iterate(d.dct)
Base.iterate(d::CIDict, i) = iterate(d.dct, i)
end

Base.length(d::CIDict) = length(d.dct)

Expand Down
7 changes: 4 additions & 3 deletions src/SASLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ read the entire file content. When called again, fetch the next `nrows` rows.
function read(handler::Handler, nrows=0)
# println("Reading $(handler.config.filename)")
elapsed = @elapsed result = read_chunk(handler, nrows)
elapsed = round(elapsed, 5)
# TODO base keyword arg should not be needed due to Compat.jl issue #567
elapsed = Compat.round(elapsed; digits = 5, base = 10)
println1(handler, "Read $(handler.config.filename) with size $(size(result, 1)) x $(size(result, 2)) in $elapsed seconds")
return result
end
Expand Down Expand Up @@ -983,7 +984,7 @@ end

# convert Float64 value into Date object
function date_from_float(x::Vector{Float64})
@compat v = Vector{Union{Date, Missing}}(uninitialized, length(x))
@compat v = Vector{Union{Date, Missing}}(undef, length(x))
for i in 1:length(x)
v[i] = isnan(x[i]) ? missing : (sas_date_origin + Dates.Day(round(Int64, x[i])))
end
Expand All @@ -992,7 +993,7 @@ end

# convert Float64 value into DateTime object
function datetime_from_float(x::Vector{Float64})
@compat v = Vector{Union{DateTime, Missing}}(uninitialized, length(x))
@compat v = Vector{Union{DateTime, Missing}}(undef, length(x))
for i in 1:length(x)
v[i] = isnan(x[i]) ? missing : (sas_datetime_origin + Dates.Second(round(Int64, x[i])))
end
Expand Down
2 changes: 1 addition & 1 deletion src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@ const VENDOR_SAS = 0x01
const FALLBACK_ENCODING = "UTF-8"
const ENCODINGS_OK_WITH_BASE_TRANSCODER = [ "UTF-8" , "US-ASCII" ]

@compat const REGULAR_STR_ARRAY(n) = Array{String}(uninitialized, n)
@compat const REGULAR_STR_ARRAY(n) = Array{String}(undef, n)
const EMPTY_STRING = ""

73 changes: 73 additions & 0 deletions test/perf_results_0.5.2/performance_0.7.0_vs_0.6.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Performance Comparison (0.7.0-beta vs 0.6.3)

## Small Data Set

Reading data_pandas/productsales.sas7bdat (140K) is 12% faster in v0.7.

v0.7
```
julia> @benchmark readsas("data_pandas/productsales.sas7bdat", verbose_level = 0)
BenchmarkTools.Trial:
memory estimate: 1.01 MiB
allocs estimate: 14727
--------------
minimum time: 1.748 ms (0.00% GC)
median time: 1.843 ms (0.00% GC)
mean time: 2.027 ms (5.61% GC)
maximum time: 58.967 ms (96.56% GC)
--------------
samples: 2458
evals/sample: 1
```

v0.6.3
```
julia> @benchmark readsas("data_pandas/productsales.sas7bdat", verbose_level = 0)
BenchmarkTools.Trial:
memory estimate: 1.07 MiB
allocs estimate: 18505
--------------
minimum time: 1.987 ms (0.00% GC)
median time: 2.150 ms (0.00% GC)
mean time: 2.367 ms (5.56% GC)
maximum time: 10.130 ms (70.77% GC)
--------------
samples: 2108
evals/sample: 1
```

## Larger Data Set

Reading data_AHS2013/topical.sas7bdat (14 MB) is 18% faster in v0.7.

v0.7
```
julia> @benchmark readsas("data_AHS2013/topical.sas7bdat", verbose_level = 0) seconds=60
BenchmarkTools.Trial:
memory estimate: 649.63 MiB
allocs estimate: 19011924
--------------
minimum time: 1.959 s (10.46% GC)
median time: 2.042 s (12.78% GC)
mean time: 2.061 s (12.59% GC)
maximum time: 2.348 s (12.17% GC)
--------------
samples: 30
evals/sample: 1
```

v0.6.3
```
julia> @benchmark readsas("data_AHS2013/topical.sas7bdat", verbose_level = 0) seconds=60
BenchmarkTools.Trial:
memory estimate: 632.36 MiB
allocs estimate: 18653427
--------------
minimum time: 2.391 s (10.82% GC)
median time: 2.520 s (13.07% GC)
mean time: 2.524 s (12.84% GC)
maximum time: 2.638 s (12.87% GC)
--------------
samples: 24
evals/sample: 1
```
7 changes: 4 additions & 3 deletions test/perf_test1.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using BenchmarkTools
using InteractiveUtils
using Printf

if length(ARGS) != 2
println("Usage: $PROGRAM_FILE <filename> <count>")
Expand All @@ -8,9 +10,8 @@ end
versioninfo()
println()

tic()
using SASLib
@printf "Loaded library in %.3f seconds\n" toq()
load_time = @elapsed using SASLib
@printf "Loaded library in %.3f seconds\n" load_time

b = @benchmark readsas($ARGS[1], verbose_level=0) samples=parse(Int, ARGS[2])
display(b)
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
x = SASLib.ObjectPool{String, UInt8}(default, 5)
@test length(x) == 5
@test size(x) == (5, )
@test endof(x) == 5
@test @compat lastindex(x) == 5
@test count(v -> v == default, x) == 5
@test count(v -> v === default, x) == 5
@test map(v -> "x$v", x) == [ "x", "x", "x", "x", "x" ]
Expand Down Expand Up @@ -239,7 +239,7 @@ Base.convert(::Type{YearStr}, v::Float64) = YearStr(string(round(Int, v)))
# Deal with v0.6/v0.7 difference
# v0.6 shows Missings.Missing
# v0.7 shows Missing
ty(x) = replace(x, "Missings.", "")
ty(x) = replace(x, "Missings." => "")

# convenient comparison routine since v0.6/v0.7 displays different order
same(x,y) = sort(ty.(string.(collect(x)))) == sort(ty.(string.(collect(y))))
Expand Down

0 comments on commit 0750500

Please sign in to comment.