Git Product home page Git Product logo

Comments (2)

mtth avatar mtth commented on September 18, 2024 1

There are several things wrong with your benchmark.

The first and most important is that you're not comparing equivalent operations: you should be comparing JSON.parse with type.toBuffer or type.encode. avro.parse generates a type from a schema, it's a pre-processing step which should only be done once per schema.

The other major problem is that micro-benchmarks are tricky to get right. v8 has many optimizations which can render your benchmark meaningless. If we tweak your code to remove any obvious pitfalls (see below), we get:

JSON: 2239ms
Avro: 2200ms

var avro = require('avsc');

var schema = {
  name: 'Pet',
  type: 'record',
  fields: [
    {name: 'kind', type: {name: 'Kind', type: 'enum', symbols: ['CAT', 'DOG']}},
    {name: 'age', type: 'int'} // To simplify preventing getting hoisted out of the loop.
  ]
};

var type = avro.parse(schema); // Done once upfront.

var start = Date.now();
for (var i = 0; i < 5000000; i++) {
  if (JSON.stringify({age: i, kind: 'CAT'}).length < 2) {
    throw new Error();
  }
}
var stop = Date.now();
console.log("\t      JSON: " + (stop - start) + "ms");

start = Date.now();
for (var i = 0; i < 5000000; i++) {
  if (type.toBuffer({age: i, kind: 'CAT'}).length < 2) {
    throw new Error();
  }
}
stop = Date.now();
console.log("\t      Avro: " + (stop - start) + "ms");

from avsc.

 avatar commented on September 18, 2024

Awww. I'm an idiot. Well, I'll be using Avro from now on then :) Thanks for the explanation haha.

Cannot wait to get this puppy across our binary websockets, she will fly.

from avsc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.