Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wotb-rs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nodes
typescript
wotb-rs
Commits
2a430bd9
Commit
2a430bd9
authored
Apr 27, 2018
by
Éloïs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[enh] add perfs tests + improve safe memCopy
parent
f9a7afaa
Pipeline
#2012
passed with stage
in 3 minutes
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
33 deletions
+81
-33
lib/index.js
lib/index.js
+1
-1
native/src/lib.rs
native/src/lib.rs
+24
-32
test.bin
test.bin
+0
-0
tests/tests_safe_perfs.js
tests/tests_safe_perfs.js
+56
-0
No files found.
lib/index.js
View file @
2a430bd9
...
...
@@ -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
;
...
...
native/src/lib.rs
View file @
2a430bd9
...
...
@@ -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_count
s
{
for
js_source
in
arg_source
s
{
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
>
{
...
...
test.bin
View file @
2a430bd9
No preview for this file type
tests/tests_safe_perfs.js
0 → 100644
View file @
2a430bd9
"
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment