Skip to content

Commit 2c6252e

Browse files
committed
Update requirements, improve tests
1 parent 7521c38 commit 2c6252e

4 files changed

Lines changed: 93 additions & 69 deletions

File tree

Project.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
authors = [
2+
"ScottPJones <scottjones@alum.mit.edu>",
23
"Dahua Lin <lindahua@gmail.com>",
34
"John M Kuhn <jmkuhn@starpower.net>",
4-
"ScottPJones <scottjones@alum.mit.edu>",
55
"Thomas Breloff <tom@breloff.com>",
66
"Alex Arslan <ararslan@comcast.net>",
77
"Chuan-Zheng Lee <czlee@stanford.edu>",
@@ -23,17 +23,17 @@ keywords = ["Strings", "Formatting"]
2323
license = "MIT"
2424
name = "Format"
2525
uuid = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
26-
version = "1.2.2"
26+
version = "1.2.0"
2727

2828
[deps]
29-
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
3029

3130
[extras]
3231
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3332
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
33+
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
3434

3535
[targets]
36-
test = ["Test", "Random"]
36+
test = ["Test", "Random", "Printf"]
3737

3838
[compat]
39-
julia = "^1.0.0"
39+
julia = "1.6"

src/Format.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ module Format
189189

190190
import Base.show
191191

192-
using Printf
193-
194192
_stdout() = stdout
195193
_codeunits(s) = Vector{UInt8}(codeunits(s))
196194
m_eval(expr) = Core.eval(@__MODULE__, expr)

test/cformat.jl

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -38,68 +38,7 @@ end
3838

3939
@time test_equality()
4040

41-
println( "\nTest speed" )
42-
43-
function native_int()
44-
for i in 1:200000
45-
@sprintf( "%10d", i )
46-
end
47-
end
48-
function runtime_int()
49-
for i in 1:200000
50-
cfmt( "%10d", i )
51-
end
52-
end
53-
function runtime_int_bypass()
54-
f = generate_formatter( "%10d" )
55-
for i in 1:200000
56-
f( i )
57-
end
58-
end
59-
60-
println( "integer @sprintf speed")
61-
@time native_int()
62-
println( "integer sprintf speed")
63-
@time runtime_int()
64-
println( "integer sprintf speed, bypass repeated lookup")
65-
@time runtime_int_bypass()
66-
67-
function native_float()
68-
set_seed!( 10 )
69-
for i in 1:200000
70-
@sprintf( "%10.4f", _erfinv( rand() ) )
71-
end
72-
end
73-
function runtime_float()
74-
set_seed!( 10 )
75-
for i in 1:200000
76-
cfmt( "%10.4f", _erfinv( rand() ) )
77-
end
78-
end
79-
function runtime_float_spec()
80-
set_seed!( 10 )
81-
fs = Format.FmtSpec("%10.4f")
82-
for i in 1:200000
83-
cfmt( fs, _erfinv( rand() ) )
84-
end
85-
end
86-
function runtime_float_bypass()
87-
f = generate_formatter( "%10.4f" )
88-
set_seed!( 10 )
89-
for i in 1:200000
90-
f( _erfinv( rand() ) )
91-
end
92-
end
93-
94-
println()
95-
println( "float64 @sprintf speed")
96-
@time native_float()
97-
println( "float64 cfmt speed")
98-
@time runtime_float()
99-
println( "float64 cfmt spec speed")
100-
@time runtime_float_spec()
101-
println( "float64 cfmt speed, bypass repeated lookup")
102-
@time runtime_float_bypass()
41+
include("speedtest.jl")
10342

10443
@testset "test commas..." begin
10544
@test cfmt( "%'d", 1000 ) == "1,000"

test/speedtest.jl

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
println( "\nTest speed" )
2+
3+
const BENCH_REP = 200_000
4+
5+
function native_int()
6+
for i in 1:BENCH_REP
7+
@sprintf( "%10d", i )
8+
end
9+
end
10+
function format_int()
11+
fmt = Printf.Format( "%10d" )
12+
for i in 1:BENCH_REP
13+
Printf.format( fmt, i )
14+
end
15+
end
16+
function runtime_int()
17+
for i in 1:BENCH_REP
18+
cfmt( "%10d", i )
19+
end
20+
end
21+
function runtime_int_spec()
22+
fs = Format.FmtSpec("%10d")
23+
for i in 1:BENCH_REP
24+
cfmt( fs, i )
25+
end
26+
end
27+
function runtime_int_bypass()
28+
f = generate_formatter( "%10d" )
29+
for i in 1:BENCH_REP
30+
f( i )
31+
end
32+
end
33+
34+
println( "integer @sprintf speed")
35+
@time native_int()
36+
println( "integer format speed")
37+
@time format_int()
38+
println( "integer cfmt speed")
39+
@time runtime_int()
40+
println( "integer cfmt spec speed")
41+
@time runtime_int_spec()
42+
println( "integer cfmt speed, bypass repeated lookup")
43+
@time runtime_int_bypass()
44+
45+
set_seed!(10)
46+
const testflts = [ _erfinv( rand() ) for i in 1:200_000 ]
47+
48+
function native_float()
49+
for v in testflts
50+
@sprintf( "%10.4f", v)
51+
end
52+
end
53+
function format_float()
54+
fmt = Printf.Format( "%10.4f" )
55+
for v in testflts
56+
Printf.format( fmt, v )
57+
end
58+
end
59+
function runtime_float()
60+
for v in testflts
61+
cfmt( "%10.4f", v)
62+
end
63+
end
64+
function runtime_float_spec()
65+
fs = Format.FmtSpec("%10.4f")
66+
for v in testflts
67+
cfmt( fs, v )
68+
end
69+
end
70+
function runtime_float_bypass()
71+
f = generate_formatter( "%10.4f" )
72+
for v in testflts
73+
f( v )
74+
end
75+
end
76+
77+
println()
78+
println( "float64 @sprintf speed")
79+
@time native_float()
80+
println( "float64 format speed")
81+
@time format_float()
82+
println( "float64 cfmt speed")
83+
@time runtime_float()
84+
println( "float64 cfmt spec speed")
85+
@time runtime_float_spec()
86+
println( "float64 cfmt speed, bypass repeated lookup")
87+
@time runtime_float_bypass()

0 commit comments

Comments
 (0)