main
 1// Copyright 2025 Google LLC
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     https://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import cronometro from 'cronometro'
16
17const STR = 'a'.repeat(1024)
18const BUF = Buffer.from(STR)
19const BUF_ARR = new Array(128).fill(null).map(() => Buffer.from(STR))
20const STR_ARR = new Array(128).fill(STR)
21
22const decoder = new TextDecoder()
23cronometro({
24  buf_arr_map_decode_join() {
25    BUF_ARR.map(decoder.decode.bind(decoder)).join('')
26  },
27  buf_arr_reduce_decode() {
28    BUF_ARR.reduce((acc, buf) => acc + decoder.decode(buf), '')
29  },
30  buf_arr_reduce_to_string() {
31    BUF_ARR.reduce((acc, buf) => acc + buf.toString('utf8'), '')
32  },
33  buf_arr_for_decode() {
34    let res = ''
35    for (const buf of BUF_ARR) {
36      res += decoder.decode(buf)
37    }
38  },
39  buf_arr_while_decode() {
40    let res = ''
41    let i = 0
42    const bl = BUF_ARR.length
43    while (i < bl) {
44      res += decoder.decode(BUF_ARR[i])
45      i++
46    }
47  },
48  buf_arr_join() {
49    BUF_ARR.join('')
50  },
51  buf_arr_concat_decode() {
52    decoder.decode(Buffer.concat(BUF_ARR))
53  },
54  str_arr_join() {
55    STR_ARR.join('')
56  },
57  str_arr_reduce() {
58    STR_ARR.reduce((acc, buf) => acc + buf, '')
59  },
60})