项目作者: glathoud

项目描述 :
Merging loops for speed in JavaScript
高级语言: JavaScript
项目地址: git://github.com/glathoud/transfun.git
创建时间: 2016-01-27T08:00:15Z
项目社区:https://github.com/glathoud/transfun

开源协议:Boost Software License 1.0

下载


transfun.js

transfun.js is a JavaScript library that lets you write map/filter/reduce code that runs much faster than the equivalent native map/filter/reduce code:

speedup

Usage

Instead of passing function arguments to the native array methods map/filter/reduce to produce a result value in 1 step:

  1. var result = arr.map((x) => x.p).filter((x) => x != null).reduce((a,b) => a + b);

transfun.js uses a 2-step approach: first generate very fast code, then call it:

  1. var appfun = map( '.p' ).filter( '!=null' ).reduce( '+' );
  2. var result = appfun( arr ); // very fast!

Usage with functions

transfun.js also supports normal function arguments:

  1. var appfun = map((x) => x.p ).filter((x) => x!=null ).reduce((out,v) => out+v );
  2. var result = appfun( arr ); // fast!

…but there is a performance cost.
However, this is still much faster than the native array methods. For more about this topic, see an article about @roman01la/understanding-transducers-in-javascript-3500d3bd9624#.9mto6edg3">transducers in JavaScript

Merging loops for speed

transfun.js automatically merges consecutive loops into one loop, then generates fast code for that loop (similar to stream fusion in Haskell).

Extensibility

A domain-specific language is used to define map/filter/reduce. With this language, library users can define other transformations: sum, and, or

For the hurried ones

…you can jump directly to the speed results

More about this

http://glat.info/transfun/

Node.js package

https://www.npmjs.com/package/transfun

License

The Boost License apply, as described in the file LICENSE.