Commit 2a430bd9 authored by Éloïs's avatar Éloïs

[enh] add perfs tests + improve safe memCopy

parent f9a7afaa
Pipeline #2012 passed with stage
in 3 minutes
......@@ -213,7 +213,7 @@ const SafeWoTB = {
var instance = Object.create(SafeWoTB)
instance.setFilePath("")
instance.setMaxCert(this.maxCerts)
let instance_content = binding.safe_mem_copy(this.maxCerts, this.nodes, this.sources);
let instance_content = binding.safe_mem_copy(this.nodes, this.issued_count, this.sources);
instance.nodes = instance_content.nodes;
instance.issued_count = instance_content.issued_count;
instance.sources = instance_content.sources;
......
......@@ -27,45 +27,36 @@ static PATH_FINDER: RustyPathFinder = RustyPathFinder {};
fn safe_mem_copy(call: Call) -> JsResult<JsObject> {
let scope = call.scope;
let max_links = try!(try!(call.arguments.require(scope, 0)).check::<JsInteger>()).value();
let mut wot = RustyWebOfTrust::new(max_links as usize);
let arg_nodes = call.arguments.require(scope, 1);
let arg_sources = call.arguments.require(scope, 2);
let _bool = try!(fill_rust_wot(scope, arg_nodes, arg_sources, &mut wot));
let mut js_nodes_array = JsArray::new(scope, wot.size() as u32);
let mut js_sources_array = JsArray::new(scope, wot.size() as u32);
let mut rs_issued_counts = vec![0; wot.size()];
for i in 0..wot.size() {
let arg_nodes = try!(try!(try!(call.arguments.require(scope, 0)).check::<JsArray>()).to_vec(scope));
let arg_issued_count = try!(try!(try!(call.arguments.require(scope, 1)).check::<JsArray>()).to_vec(scope));
let arg_sources = try!(try!(try!(call.arguments.require(scope, 2)).check::<JsArray>()).to_vec(scope));
let mut js_nodes_array = JsArray::new(scope, arg_nodes.len() as u32);
let mut js_issued_count_array = JsArray::new(scope, arg_issued_count.len() as u32);
let mut js_sources_array = JsArray::new(scope, arg_sources.len() as u32);
let mut i: u32 = 0;
for js_node in arg_nodes {
let _bool = try!(JsArray::set(
*js_nodes_array.deref_mut(),
i as u32,
JsBoolean::new(scope, wot.is_enabled(NodeId(i as usize)).unwrap()),
*js_nodes_array.deref_mut(),
i,
try!(js_node.check::<JsBoolean>()),
));
let sources = wot.get_links_source(NodeId(i as usize)).unwrap();
let mut js_sources = JsArray::new(scope, sources.len() as u32);
let mut j: u32 = 0;
for source in sources {
rs_issued_counts[source.0] += 1;
let _bool = try!(JsArray::set(
*js_sources.deref_mut(),
j,
JsInteger::new(scope, source.0 as i32),
));
j += 1;
}
i += 1;
}
let mut i: u32 = 0;
for js_issued_count in arg_issued_count {
let _bool = try!(JsArray::set(
*js_sources_array.deref_mut(),
i as u32,
js_sources,
*js_issued_count_array.deref_mut(),
i,
try!(js_issued_count.check::<JsInteger>()),
));
i += 1;
}
let mut js_issued_count_array = JsArray::new(scope, wot.size() as u32);
let mut i: u32 = 0;
for issued_count in rs_issued_counts {
for js_source in arg_sources {
let _bool = try!(JsArray::set(
*js_issued_count_array.deref_mut(),
i,
JsInteger::new(scope, issued_count as i32),
*js_sources_array.deref_mut(),
i,
try!(js_source.check::<JsArray>()),
));
i += 1;
}
......@@ -74,6 +65,7 @@ fn safe_mem_copy(call: Call) -> JsResult<JsObject> {
let _bool = try!(JsObject::set(*js_wot.deref_mut(), "issued_count", js_issued_count_array,));
let _bool = try!(JsObject::set(*js_wot.deref_mut(), "sources", js_sources_array,));
Ok(js_wot)
}
fn unsafe_mem_copy_from_safe(call: Call) -> JsResult<JsInteger> {
......
No preview for this file type
"use strict";
const addon = require('./../lib/index');
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var should = require('should');
testsSafePerfs()
function testsSafePerfs() {
function newInstance(launchSafeTests) {
return () => {
let wot = addon.newEmptySafeMemoryInstance(100);
launchSafeTests(wot);
}
}
describe("wotb-rs performances tests", () => {
describe('Basic operations', newInstance((wot) => {
it('should add 1_000_000 nodes', function() {
for (let i = 0; i < 1000000; i++) {
should.equal(wot.addNode(), i);
}
should.equal(wot.getWoTSize(), 1000000);
});
it('should add 500_000 links', function() {
for (let i = 0; i < 500000; i++) {
for (let j = 0; j < 1; j++) {
wot.addLink(i, Math.random*(999999))
}
}
});
it('should make a real mem copy', function() {
let wot2 = wot.memCopy();
wot2.addNode();
wot2.addLink(0, 1);
should.equal(wot.getWoTSize(), 1000000);
should.equal(wot.existsLink(0, 1), false);
});
it('should make a unsafe mem copy', function() {
var unsafe_wot = wot.unsafeMemCopy();
});
it('should make a unsafe mem copy and copy them', function() {
var unsafe_wot = wot.unsafeMemCopy();
unsafe_wot.memCopy();
});
}));
});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment