benchmarks/string: Added benchmark for Array.to_s
[nit.git] / benchmarks / strings / array_to_s_vars / array_to_s_buffer.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
9 # another product.
10
11 # Implementation of Array::to_s with FlatBuffer exclusively
12 #
13 # To be used as a Mixin at compile-time for benchmarking purposes.
14 module array_to_s_buffer
15
16 redef class Array[E]
17 redef fun to_s: String do
18 var s = new FlatBuffer
19 var i = 0
20 var l = length
21 var its = _items
22 while i < l do
23 var e = its[i]
24 if e != null then s.append(e.to_s)
25 i += 1
26 end
27 return s.to_s
28 end
29 end