npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fast-buffer

v0.0.1

Published

A faster way of handling buffers.

Downloads

6

Readme

Node Fast Buffer Build Status

NPM

A faster way of handling Buffers, or so I say.

Notice: This is NOT a real buffer. But works faster for certain use cases.

Performance

Node Buffer

new Buffer from buffer     x 260,001 ops/sec ±2.06% (79 runs sampled)
new Buffer from byte array x 215,698 ops/sec ±2.31% (73 runs sampled)
new Buffer from size       x 277,193 ops/sec ±2.09% (91 runs sampled)

Fast Buffer

new fastBuffer from buffer     x   189,329 ops/sec ±2.73% (74 runs sampled)
new fastBuffer from byte array x 3,486,441 ops/sec ±0.28% (93 runs sampled)
new fastBuffer from size       x 1,726,193 ops/sec ±0.40% (97 runs sampled)

Faster Buffer

new fasterBuffer from buffer     x    212,569 ops/sec ±2.41% (81 runs sampled)
new fasterBuffer from byte array x  7,866,879 ops/sec ±0.19% (99 runs sampled)
new fasterBuffer from size       x 14,760,543 ops/sec ±0.42% (100 runs sampled)

Installing

$ npm install fast-buffer --save

Installing the latest version

$ npm install git+https://github.com/majimboo/node-fast-buffer.git

or for those without git

$ npm install http://github.com/majimboo/node-fast-buffer/tarball/master

Usage - fastBuffer

var fastBuffer = require('fast-buffer').fastBuffer;
var buf = new fastBuffer(5);
buf.writeUInt8(0x01);
buf.writeUInt8(0x02);
buf.writeUInt8(0x03);
buf.writeUInt8(0x04);
buf.writeUInt8(0x05);

var buf = new fastBuffer([0x01, 0x02, 0x03, 0x04, 0x05]);
var buf = new fastBuffer(new Buffer([0x01, 0x02, 0x03, 0x04, 0x05]));

// create new buffer
var buf = new fastBuffer([0x05, 0x07, 0x02, 0x05, 0x09]);

// do some processing like 
// - encrypt the buffer
for (var i = 0; i < buf.length; i++) {
  buf[i] ^= 0x02;
  buf[i] ^= 0x03;
  buf[i] ^= 0x01;
  buf[i] ^= 0x02;
  buf[i] ^= 0x03;
}
// - append the size
var buf_w_size = new fastBuffer([0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
buf.copy(buf_w_size, 1);
buf_w_size.writeUInt8(buf_w_size.length, 0);

// send data
socket.write(buf_w_size.encode());

Usage - fasterBuffer

var fasterBuffer = require('fast-buffer').fasterBuffer;
var mainBuf = new fasterBuffer(5);
var buf = mainBuf.bytes;
buf.writeUInt8(0x01);
buf.writeUInt8(0x02);
buf.writeUInt8(0x03);
buf.writeUInt8(0x04);
buf.writeUInt8(0x05);

var buf = new fasterBuffer([0x01, 0x02, 0x03, 0x04, 0x05]);
var buf = new fasterBuffer(new Buffer([0x01, 0x02, 0x03, 0x04, 0x05]));

Problem

I needed a fast protocol for a MMOG server I was developing in Node.JS. My workflow was creating buffers, writing bits into it, encrypting, then sent the data with socket.write().

I noticed the performance difference when I was doing some benchmark which results can be seen here.

How slow?

var buf = new Buffer([0x00, 0x01, 0x03, 0x04]);
socket.write(buf);

When benchmarked gives:

buffer x 112,474 ops/sec ±11.07% (52 runs sampled)

Solution

As UTF-8 strings, it would be like

var buf = '\x00\x01\x03\x04';
socket.write(buf);

Now let us see some benchmark:

utf-8  x 1,629,796 ops/sec ±29.13% (54 runs sampled)

You can try the benchmark here by running

node benchmark/buffer-vs-utf8

As you can see, there is a huge difference in speed, using utf-8 strings gives you about x14 more performance than using buffers.

WORK IN PROGRESS - TBC#