• Stars
    star
    248
  • Rank 163,560 (Top 4 %)
  • Language
    JavaScript
  • Created about 10 years ago
  • Updated about 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Boosted Performance Array

PowerArray

Turns out that you can re-write some of the methods of Array to obtain a much better performance than the native methods. In particular, Array.forEach seems to perform pretty badly.

Note: the overridden methods of PowerArray break compliance, the focus is on performance so take a look at the caveat section below.

It looks as if a for loop with cached length is the fastest way of iterating.

var i, len = array.length;
for (i = 0; i < len; i += 1) {
  someFun(array[i]);
}

So I rewrote the Array class as PowerArray and implemented the above mechanism in PowerArray.forEach with surprising results.

The results are as follows: PowerArray.forEach is averagely 5 times faster than native Array.

This is only a proof of concept.

Install with npm install powerarray

Proposed Usage

Particularly useful for arrays that need processing on all elements often, or for numeric arrays utilized as indexes for Collections of data.

Methods

All Array native methods are available through PowerArray. The following methods are either extending or overriding the native Array class.

PowerArray.forEach: utilizes a for loop for iteration, takes a callback which receives an element and the index of that element.

PowerArray.map: utilizes a for loop to return a PowerArray of mapped values, takes a callback processing function argument.

PowerArray.binarySearch: performs a binary search on the elements of the array, only relevant if the array only consists of numbers. Thanks to Oliver Caldwell's post for a quick version of the algorithm. Also note the contribution of Yehonatan and other authors of comments to the post which helped to optimise the implementation of binary search further.

PowerArray.numericSort: sorts array (if array only contains integers), useful for utilizing binarySearch. Optional sorting function argument.

PowerArray.addAndSort: adds a new value and sorts the array automatically

Contribution

Pull requests are more than welcome, just make sure to add a test in tests/test.js (and that it passes it obviously).

Caveats

Thanks to David Souther for documenting these:

  1. No this context in fn calls, handle your own binding.
  2. No determination if i is a member of PowerArray (eg for sparse arrays, [2, 4, , 6])
  3. No exception is thrown when the callback isn't callable.

There may be more, please feel free to flag those or include them yourself through a pull request.

More Repositories

1

LokiJS

javascript embeddable / in-memory database
JavaScript
6,738
star
2

pycv

Website of the book "Learn OpenCV 3 with Python"
Python
543
star
3

mimir

bag-of-words calculator in javascript
JavaScript
137
star
4

fundb

Functional programming based database engine
JavaScript
38
star
5

classify-text

proof of concept of text classification with mimir and brain
JavaScript
36
star
6

redisvue

real-time monitor and keys analytics for redis
Vue
32
star
7

jotun

convert javascript object to numerical representation (VSM)
JavaScript
20
star
8

dog-project

Jupyter Notebook
11
star
9

aind2-rnn

udacity recurrent neural network project
Jupyter Notebook
10
star
10

armour

prevent side-effects function wrapper
JavaScript
10
star
11

lokijs-server

lokijs tcp server
JavaScript
9
star
12

udacity-ec2-gpu

terraform project to launch a gpu ec2 instance for deep learning network training
HCL
9
star
13

opencv-mediapipe-hand-gesture-recognition

generate training data, train and classify a deep learning model for hand gesture recognition
Jupyter Notebook
7
star
14

lokijs-client

tcp client for lokijs
JavaScript
7
star
15

csv-loader

csv-loader for js
JavaScript
6
star
16

baldr

jekyll-style statically generated website with angular and requirejs
CSS
6
star
17

jumble

ultra-efficient javascript serialization library
JavaScript
5
star
18

paladin

Javascript composition and delegation library
JavaScript
4
star
19

cv_ml

computer vision and machine learning with opencv, sklearn, keras
Python
4
star
20

snaptun

lokijs http server wrapper
JavaScript
4
star
21

aind-sudoku

Python
3
star
22

lokijs-utils

utilities for lokijs
JavaScript
3
star
23

aind-cv-capstone

capstone project for aind cv concentration
Jupyter Notebook
3
star
24

gordian

node testing framework
JavaScript
3
star
25

autoform

nodejs server side utility to generate form elements with JSON form descriptors
JavaScript
3
star
26

AIND-Isolation

Python
3
star
27

skrymir

LokiJS v2.0 experimental repository
JavaScript
3
star
28

sleipnir

LokiJS tcp server
3
star
29

streamlog

Immutable events as a Stream, Log and Database: self-materializing and replicating views for distributed systems
JavaScript
3
star
30

dis

Go
2
star
31

snaptun-cli

command line client for snaptun
JavaScript
2
star
32

miniss

A slim javascript/JSON to css processor. Ideal for building based on a common CSS.
JavaScript
2
star
33

lokijs.org

website code
HTML
2
star
34

num-js

numpy-like lib
JavaScript
2
star
35

forward

forwarding redis keys into the aether
Go
2
star
36

ann

artificial neural networks implementation using SGD
JavaScript
2
star
37

nibiru

run lambda locally
JavaScript
2
star
38

classifly

example of JS Object classification using brain (ANN), mimir (BOW) and jotun (objects to vector)
1
star
39

techfort.com

tech-fort.com website
JavaScript
1
star
40

bloki

express angular blogging engine with lokijs database
JavaScript
1
star
41

aind-cv-mimicme

JavaScript
1
star
42

go-demo

this repo is a hello world http server that only serves as a sample go app for building go apps with jenkins. If you are learning jenkins you can use this too
Go
1
star
43

Sigyn

android nosql embeddable datastore
Java
1
star
44

sendyoulater

Go
1
star
45

AndroidMongolab

a tiny library for mongolab connection with android
Java
1
star
46

hbow

bag of words in haskell (study)
Haskell
1
star
47

norns

replicable redis-like key value store for node
JavaScript
1
star
48

doomsword

doomsword web site code
CSS
1
star
49

heavy-metal-js

Performance findings, Code robustness: Speed and Power. Heavy Metal.
1
star
50

streamlogdb

event stream as log and database
C++
1
star
51

wyrdtales

Go
1
star