From 024bbce1a6aa4b0ed68f01fa152c008c8f84d10a Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Sun, 27 Apr 2014 21:56:08 -0400 Subject: [PATCH] remove some typeasserts that were causing severe performance issues --- base/printf.jl | 12 ++++++------ test/perf/micro/perf.jl | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/base/printf.jl b/base/printf.jl index 8939cc3db6c7e..515e618db5b60 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -242,11 +242,11 @@ function gen_d(flags::ASCIIString, width::Int, precision::Int, c::Char) else fn = :decode_dec end - push!(blk.args, :((do_out, args) = $fn(out, $x, $flags, $width, $precision, $c)::(Bool,Tuple))) + push!(blk.args, :((do_out, args) = $fn(out, $x, $flags, $width, $precision, $c))) ifblk = Expr(:if, :do_out, Expr(:block)) push!(blk.args, ifblk) blk = ifblk.args[2] - push!(blk.args, :((len, pt, neg) = args::(Int32,Int32,Bool))) + push!(blk.args, :((len, pt, neg) = args)) # calculate padding width -= length(prefix) space_pad = width > max(1,precision) && '-' in flags || @@ -309,11 +309,11 @@ function gen_f(flags::ASCIIString, width::Int, precision::Int, c::Char) x, ex, blk = special_handler(flags,width) # interpret the number if precision < 0; precision = 6; end - push!(blk.args, :((do_out, args) = fix_dec(out, $x, $flags, $width, $precision, $c)::(Bool,Tuple))) + push!(blk.args, :((do_out, args) = fix_dec(out, $x, $flags, $width, $precision, $c))) ifblk = Expr(:if, :do_out, Expr(:block)) push!(blk.args, ifblk) blk = ifblk.args[2] - push!(blk.args, :((len, pt, neg) = args::(Int32,Int32,Bool))) + push!(blk.args, :((len, pt, neg) = args)) # calculate padding padding = nothing if precision > 0 || '#' in flags @@ -373,11 +373,11 @@ function gen_e(flags::ASCIIString, width::Int, precision::Int, c::Char) # interpret the number if precision < 0; precision = 6; end ndigits = min(precision+1,BUFLEN-1) - push!(blk.args, :((do_out, args) = ini_dec(out,$x,$ndigits, $flags, $width, $precision, $c)::(Bool,Tuple))) + push!(blk.args, :((do_out, args) = ini_dec(out,$x,$ndigits, $flags, $width, $precision, $c))) ifblk = Expr(:if, :do_out, Expr(:block)) push!(blk.args, ifblk) blk = ifblk.args[2] - push!(blk.args, :((len, pt, neg) = args::(Int32,Int32,Bool))) + push!(blk.args, :((len, pt, neg) = args)) push!(blk.args, :(exp = pt-1)) expmark = c=='E' ? "E" : "e" if precision==0 && '#' in flags diff --git a/test/perf/micro/perf.jl b/test/perf/micro/perf.jl index 943bc9992adfe..aaada737b938c 100644 --- a/test/perf/micro/perf.jl +++ b/test/perf/micro/perf.jl @@ -138,10 +138,13 @@ end @unix_only begin function printfd(n) - open("/dev/null","w") do io + io = open("/dev/null","w") + try for i = 1:n @printf(io,"%d %d\n",i,i+1) end + finally + close(io) end end