<commit_before>import * as assert from 'assert'
import * as Benchmark from 'benchmark'
import { Context, getDefaultContext, getContextEntry, string, number } from '../src/index'

const suite = new Benchmark.Suite()
const c: Context = getDefaultContext(string)

describe('perf', () => {
  ;(it('concat([a]) should be faster than concat(a)', done => {
    suite
      .add('concat(e)', function() {
        c.concat(getContextEntry('key', number))
      })
      .add('concat([e])', function() {
        c.concat([getContextEntry('key', number)])
      })
      .on('cycle', function(event: any) {
        console.log(String(event.target))
      })
      .on('complete', function(this: any) {
        assert.deepEqual(this.filter('fastest').map('name'), ['concat([e])'])
        done()
      })
      .run({ async: true })
  }) as any).timeout(20000)
})<commit_msg>exhibit that manual array copying way faster than idiomatic js<commit_after>import * as Benchmark from 'benchmark'
import * as assert from 'assert'

import { Context, getContextEntry, getDefaultContext, number, string } from '../src/index'

const suite = new Benchmark.Suite()
const c: Context = getDefaultContext(string)

const appendNext = (arr: any[], e: any) => {
  const len = arr.length
  const res = Array(len + 1)
  for (let i = 0; i < len; i++) {
    res[i] = arr[i]
  }
  res[len] = e
  return res
}

describe('perf', () => {
  ;(it('concat([a]) should be faster than concat(a)', done => {
    suite
      .add('concat(e)', function() {
        c.concat(getContextEntry('key', number))
      })
      .add('concat([e])', function() {
        c.concat([getContextEntry('key', number)])
      })
      .add('manual appendNext function', function() {
        appendNext(c, getContextEntry('key', number))
      })
      .on('cycle', function(event: any) {
        console.log(String(event.target))
      })
      .on('complete', function(this: any) {
        assert.deepEqual(this.filter('fastest').map('name'), ['concat([e])'])
        done()
      })
      .run({ async: true })
  }) as any).timeout(20000)
})
{'fraction_non_alphanumeric': 0.1826045170591062, 'fraction_numerical': 0.005766458433445459, 'mean_word_length': 3.164, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1399631', 'n_tokens_mistral': 664, 'n_tokens_neox': 650, 'n_words': 158}