UNPKG

1.25 kBJavaScriptView Raw
1'use strict'
2const Benchmark = require('benchmark')
3const suite = new Benchmark.Suite
4
5function Complex() {
6 this.bar = 'foo'
7 this.foo = new Array(100).fill(0).map(e => Math.random())
8}
9
10Complex.prototype.method = function() {}
11
12const a = {b: 'hello', c: {foo: 'bar', bar: 'foo', error: new Error('Test')}, complex: new Complex()}
13
14a.a = a
15a.c.complex = a.complex
16a.env = process.env
17
18const soyuka_clone = require('../dist/fclone.js')
19const clone = require('clone')
20const deepcopy = require('deepcopy')
21const jsonstringifysafe = require('json-stringify-safe')
22const jsan = require('jsan')
23const circularjson = require('circular-json-es6')
24
25suite
26.add('fclone', function() {
27 let b = soyuka_clone(a)
28})
29.add('fclone + json.stringify', function() {
30 let b = JSON.stringify(soyuka_clone(a))
31})
32.add('jsan', function() {
33 let b = jsan.stringify(a)
34})
35.add('circularjson', function() {
36 let b = circularjson.stringify(a)
37})
38.add('deepcopy', function() {
39 let b = deepcopy(a)
40})
41.add('json-stringify-safe', function() {
42 let b = jsonstringifysafe(a)
43})
44.on('cycle', function(event) {
45 console.log(String(event.target))
46})
47.on('complete', function() {
48 console.log('Fastest is ' + this.filter('fastest').map('name'))
49})
50.run({ 'async': true })