11# The Computer Language Benchmarks Game
22# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
3- #
4-
5- mutable struct PushVector{T, A<: AbstractVector{T} } <: AbstractVector{T}
6- v:: A
7- l:: Int
8- end
9-
10- PushVector {T} () where {T} = PushVector (Vector {T} (undef, 0 ), 0 )
11-
12- Base. IndexStyle (:: Type{PushVector{<:Any, A}} ) where {A} = IndexStyle (A)
13- Base. length (v:: PushVector ) = v. l
14- Base. size (v:: PushVector ) = (v. l,)
15- @inline function Base. getindex (v:: PushVector , i)
16- @boundscheck checkbounds (v, i)
17- @inbounds v. v[i]
18- end
19-
20- function Base. push! (v:: PushVector , i)
21- v. l += 1
22- if v. l > length (v. v)
23- resize! (v. v, v. l * 2 )
24- end
25- v. v[v. l] = i
26- return v
27- end
28-
29- function Base. write (v:: PushVector{UInt8} , s:: String )
30- for c in codeunits (s)
31- push! (v, c)
32- end
33- end
34- Base. write (v:: PushVector{UInt8} , c:: UInt8 ) = push! (v, c)
353
364const line_width = 60
375
@@ -60,7 +28,6 @@ function repeat_fasta(io, src, n)
6028 k = length (src)
6129 s = string (src, src, src[1 : (n % k)])
6230 I = Iterators. cycle (src)
63- # I = Iterators.cycle(codeunits(src))
6431 col = 1
6532 count = 1
6633 c, state = iterate (I)
@@ -70,12 +37,12 @@ function repeat_fasta(io, src, n)
7037 c, state = iterate (I, state)
7138 write (io, c % UInt8)
7239 if col == line_width
73- write (io, ' \n ' % UInt8 )
40+ write (io, ' \n ' )
7441 col = 0
7542 end
7643 count += 1
7744 end
78- write (io, ' \n ' % UInt8 )
45+ write (io, ' \n ' )
7946 return
8047end
8148
@@ -110,17 +77,14 @@ function random_fasta(io, symb, pr, n)
11077 return
11178end
11279
113- function perf_fasta (_n= 25000000 , _io = stdout )
114- io = PushVector {UInt8} ()
80+ function perf_fasta (_n= 25000000 , io = stdout )
11581 write (io, " >ONE Homo sapiens alu\n " )
11682 repeat_fasta (io, alu, 2 n)
11783
11884 write (io, " >TWO IUB ambiguity codes\n " )
11985 random_fasta (io, iub1, iub2, 3 n)
12086 write (io, " >THREE Homo sapiens frequency\n " )
12187 random_fasta (io, homosapiens1, homosapiens2, 5 n)
122- z = resize! (io. v, length (io))
123- write (_io, z)
12488end
12589
12690n = parse (Int,ARGS [1 ])
0 commit comments