Socket
Socket
Sign inDemoInstall

node-v8-clone

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-v8-clone - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

examples/example2.js

71

bench/bench.js
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
obj = {a: '1', b: '2', c: '3', x: 1, y: 2, z: 3};
// obj1: 5 sting keys and values
obj1 = {'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd', 'e': 'e'};
// obj2: 5 integer keys and values
obj2 = {1: 1, 2: 2, 3: 3, 4: 4, 5: 5};
// obj3: 1000 string keys and values
obj3 = {};
for (var i = 0; i < 1000; i++) {
//obj[i + ' ' + i] = i + ' ' + i;
obj3['_' + i] = '_' + i;
}
// obj4: 1000 integer keys and values
obj4 = {};
for (var i = 0; i < 1000; i++) {
obj4[i] = i;
}
// node-v8-clone

@@ -19,24 +31,16 @@ clone = require('..').clone;

// static cloner
var parts = [];
for (var j in obj) if (obj.hasOwnProperty(j)) {
parts.push('"' + j + '": obj["' + j + '"]');
function createStatic(obj) {
var parts = [];
for (var j in obj) if (obj.hasOwnProperty(j)) {
parts.push('"' + j + '": obj["' + j + '"]');
}
var code = 'return {' + parts.join(',') + '}';
return new Function('obj', code);
}
var code = 'return {' + parts.join(',') + '}';
console.log(code);
var static = new Function('obj', code);
static1 = createStatic(obj1);
static2 = createStatic(obj2);
static3 = createStatic(obj3);
static4 = createStatic(obj4);
// add tests
suite.add('regular cloner', function() {
regular(obj);
});
suite.add('regular own cloner', function() {
regular_own(obj);
});
suite.add('static cloner', function() {
static(obj);
});
suite.add('node-v8-clone cloner', function() {
clone(obj);
});
// add listeners
var suite = new Benchmark.Suite;
suite.on('cycle', function(event) {

@@ -48,3 +52,22 @@ console.log(String(event.target));

});
// run async
suite.add('obj1 regular cloner', 'regular(obj1)');
suite.add('obj1 regular own cloner', 'regular_own(obj1)');
suite.add('obj1 static cloner', 'static1(obj1)');
suite.add('obj1 node-v8-clone cloner', 'clone(obj1)');
suite.add('obj2 regular cloner', 'regular(obj2)');
suite.add('obj2 regular own cloner', 'regular_own(obj2)');
suite.add('obj2 static cloner', 'static2(obj2)');
suite.add('obj2 node-v8-clone cloner', 'clone(obj2)');
suite.add('obj3 regular cloner', 'regular(obj3)');
suite.add('obj3 regular own cloner', 'regular_own(obj3)');
suite.add('obj3 static cloner', 'static3(obj3)');
suite.add('obj3 node-v8-clone cloner', 'clone(obj3)');
suite.add('obj4 regular cloner', 'regular(obj4)');
suite.add('obj4 regular own cloner', 'regular_own(obj4)');
suite.add('obj4 static cloner', 'static4(obj4)');
suite.add('obj4 node-v8-clone cloner', 'clone(obj4)');
suite.run({ 'async': true });
{
"name": "node-v8-clone",
"version": "0.1.0",
"version": "0.1.1",
"description": "UNSTABLE yet. Exposed v8 clone function for node.js.",
"main": "build/Release/clone",
"scripts": {
"test": "mocha",
"test": "mocha || node_modules/.bin/mocha",
"install": "node-gyp rebuild"

@@ -23,4 +23,5 @@ },

"devDependencies": {
"benchmark": "~1.0.0"
"benchmark": "~1.0.0",
"mocha": "~1.7.0"
}
}

@@ -10,8 +10,11 @@ var assert = require("assert")

assert.equal(b, null);
a = true;
assert.equal(a, true);
assert.equal(b, null);
});
it('should clone undefined', function(){
var a = null;
var a = undefined;
var b = clone(a);
assert.equal(a, null);
assert.equal(b, null);
assert.equal(a, undefined);
assert.equal(b, undefined);
});

@@ -23,3 +26,15 @@ it('should clone numbers', function(){

assert.equal(b, 1);
a = 2;
assert.equal(a, 2);
assert.equal(b, 1);
});
it('should clone number objects', function(){
var a = new Number(1);
var b = clone(a);
assert.equal(a, 1);
assert.equal(b, 1);
a = new Number(2);
assert.equal(a, 2);
assert.equal(b, 1);
});
it('should clone objects', function(){

@@ -26,0 +41,0 @@ var a = {x : 1, y: 2};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc