-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
65 lines (53 loc) · 1.81 KB
/
index.mjs
File metadata and controls
65 lines (53 loc) · 1.81 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import * as arrow from 'apache-arrow'
import * as df from 'danfojs-node'
const nrow = 1e6
const largeData = Array.from({ length: nrow }, (_, id) => ({
id: id
, prop1: Math.random() * nrow
, prop2: Math.random() * nrow
, prop3: Math.random() * nrow + ''
}))
const arrow_data = arrow.Table.new(
// data
[
arrow.Uint32Vector.from(largeData.map(x => x.id)),
arrow.Float64Vector.from(largeData.map(x => x.prop1)),
arrow.Float64Vector.from(largeData.map(x => x.prop2)),
arrow.Utf8Vector.from(largeData.map(x => x.prop3)),
],
// names
['id', 'prop1', 'prop2', 'prop3']
)
const df_data = new df.DataFrame(largeData)
// prop2 greater than 123.456
console.log('test1: prop2 greater than 12345.67890')
// Arrow
console.time('arrow')
const arrow_result = arrow_data.filter(arrow.predicate.col('prop2').gt(12345.67890))
console.timeEnd('arrow')
// With Danfo
console.time('danfo')
const danfo_result = df_data.query({ 'column': 'prop2', 'is': '>', 'to': 12345.67890 })
console.timeEnd('danfo')
// Vanilla JS
console.time('plain Array filter')
const plain_result = largeData.filter(x => x.prop2 > 12345.67890)
console.timeEnd('plain Array filter')
// prop3 has string 666
console.log('test2: prop3 has string 666')
// Arrow
console.time('arrow')
const arrow_result_str = arrow_data.filter(x => x.prop3.includes('666'))
console.timeEnd('arrow')
// // With Danfo -> not supported!
// console.time('danfo')
// const danfo_result_str = df_data.query({ 'column': 'prop2', 'is': '>', 'to': 12345.67890 })
// console.timeEnd('danfo')
// Vanilla JS
console.time('plain Array filter')
const plain_result_str = largeData.filter(x => x.prop3.includes('666'))
console.timeEnd('plain Array filter')
//Outputs
// console.log(arrow_result.toArray())
// danfo_result.print()
// console.log(plain_result)