<commit_before>/**
 * Created by tushar.mathur on 06/11/16.
 */

import * as assert from 'assert'
import {Suite} from 'benchmark'
import {SafeValue} from '../src/lib/SafeValue'
import {toSafeFunction} from '../src/lib/ToSafeFunction'

function addThis (b: number) {
  this.a = this.a + b
  return this
}
const safelyAddThis = toSafeFunction(addThis)

function test (message: string, f: Function) {
  assert.deepStrictEqual(f().value.a, 102, message)
}

export function testFunction (): SafeValue<any> {
  return safelyAddThis.call({a: 100}, 2)
}

test('class-based', testFunction)

export function bm_tryCatch (suite: Suite) {
  return suite.add('tryCatch', testFunction)
}<commit_msg>test(trycatch): update benchmarks to return a value between 1k and 10k<commit_after>/**
 * Created by tushar.mathur on 06/11/16.
 */
import * as assert from 'assert'
import {Suite} from 'benchmark'
import {SafeValue} from '../src/lib/SafeValue'
import {toSafeFunction} from '../src/lib/ToSafeFunction'
import {array} from './lib'

function addThis (b: number) {
  this.a = this.a + b
  if (this.a % 2 === 0) {
    throw 'ERROR'
  }
  return this
}
const safelyAddThis = toSafeFunction(addThis)

function test (message: string, f: Function) {
  assert.deepStrictEqual(f(), [
    new SafeValue('ERROR'),
    new SafeValue({a: 101}),
    new SafeValue('ERROR')
  ], message)
}


export function testFunction (arr: number[]): Array<SafeValue<any>> {
  const results = []
  for (var i = 0; i < arr.length; ++i) {
    results.push(safelyAddThis.call({a: 100}, i))
  }
  return results
}

test('class-based', () => testFunction([0, 1, 2]))

const arr = array(1e3)
export function bm_tryCatch (suite: Suite) {
  return suite.add('tryCatch', () => testFunction(arr))
}
{'fraction_non_alphanumeric': 0.15481651376146788, 'fraction_numerical': 0.020642201834862386, 'mean_word_length': 4.27190332326284, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7454237', 'n_tokens_mistral': 627, 'n_tokens_neox': 594, 'n_words': 167}