-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathfast-elements.js
executable file
·37 lines (29 loc) · 931 Bytes
/
fast-elements.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node --allow-natives-syntax
'use strict';
var test = require('tap').test;
function hasFastElements(obj) {
/*jshint ignore:start*/
return %HasFastSmiElements(obj) ||
%HasFastSmiOrObjectElements(obj) ||
%HasFastObjectElements(obj) ||
%HasFastDoubleElements(obj) ||
%HasFastHoleyElements(obj);
/*jshint ignore:end*/
}
test('\narray that was not pre-allocated but grown on demand', function (t) {
var arr = [];
//10,000,000
var len = 10000000;
while(len--) {
arr.push(len);
}
t.ok(hasFastElements(arr), 'to 10,000,000 elements has fast elements')
t.end()
})
test('\narrays that were pre-allocated to hold a specific number of elements', function (t) {
var a = new Array(99999);
var b = new Array(100000);
t.ok(hasFastElements(a), 'to 99,999 elements has fast elements')
t.ok(!hasFastElements(b), 'to 100,000 elements has no fast elements')
t.end()
})