1 | 'use strict'
|
2 | const Benchmark = require('benchmark')
|
3 | const suite = new Benchmark.Suite
|
4 |
|
5 | function Complex() {
|
6 | this.bar = 'foo'
|
7 | this.foo = new Array(100).fill(0).map(e => Math.random())
|
8 | }
|
9 |
|
10 | Complex.prototype.method = function() {}
|
11 |
|
12 | const a = {b: 'hello', c: {foo: 'bar', bar: 'foo', error: new Error('Test')}, complex: new Complex()}
|
13 |
|
14 | a.a = a
|
15 | a.c.complex = a.complex
|
16 | a.env = process.env
|
17 |
|
18 | const soyuka_clone = require('../dist/fclone.js')
|
19 | const clone = require('clone')
|
20 | const deepcopy = require('deepcopy')
|
21 | const jsonstringifysafe = require('json-stringify-safe')
|
22 | const jsan = require('jsan')
|
23 | const circularjson = require('circular-json-es6')
|
24 |
|
25 | suite
|
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 })
|