cosmic realms

a coder blog

Benchmark of node.js JSON Validation Modules Part 2

Below are benchmark results for several node.js JSON validation modules.

This is an update to a post I made 2 years ago.

The following modules are benchmarked:

All modules validate with the JSON schema described here: except for joi which uses a custom schema.

I used the latest schema version supported by each module. This is noted as (v2) (v3) or (v4).



tv4 appears to be the fastest, but it only supports the very latest v4 JSON schema version. So if you have older schema documents, you'll need to go with one of the others.

Jayschema takes the 'slowest validator' crown away from JSV. I'd avoid using it if performance matters to your application.

It should be noted that joi doesn't support the JSON schema specification. Joi uses a custom schema which does not support checking for unique array items or evenly divisible numbers.

Lastly, amanda only supports async validation and so that test includes some additional overhead in dealing with callbacks.

Source Code

Full source code for all the tests can be found here:

Hand of Cards

About 2 weeks ago I launched my new web game World of Card Games

I started working on it back in December 2011. I took a month off here and there, so it probably took about 10 months of actual full time work.

One of the toughest problems I faced was getting a hand of cards to show up nicely fanned out in an arc. You know, like you would hold them real life.

My knowledge of math is pretty limited and things like cosines and tangents are totally foreign to me.

Thus, I spent many, many days on IRC and varous websites seeking assistance and learning.

After a ton of work, I was finally able to get this demo coded correctly:

Number of Cards:13
Card Spacing:0.20
Arc Radius:400
view source code

Notice how the cards stick to the base lines, regardless of how you adjust the sliders or which direction the cards are facing (NWSE buttons at top right).

This "stay in place" concept was critical. Without that it would have been quite difficult to implement into the game.

I'd like to say I learned a lot, but that would be dishonest. I still don't really understand the mathmatical concepts in use here well enough to know when or how to apply them to future problems.

My next game will likely be WebGL based. While the game itself will be mostly 2D, I'm almost certainly going to need to learn a lot more math in order to do the things I want to do.

I am actually looking forward to it though. I've always liked math and I enjoy learning, so it should be fun.

I want to thank the folks in #math on and David Gouveia for all their help.

Custom Cursor Support Gotchas

Looking to add a custom cursor to your web page or HTML5 game?

Be prepared for some significant pain... and not just with IE.

This post details the current state of custom cursor support.
Multiple browsers are tested on Linux, Windows and Mac OS X.

The following CSS is being used:

	.pointer {
		cursor: url("/cursors/pointer.cur"), auto;

	.pointerDown { 
		cursor: url("/cursors/pointerDown.cur"), auto;

	.arrow { 
		ursor: url("/cursors/arrow.cur"), auto;

Note: A small glitch may occur once during each test, while the browser loads the cursor. Thus each test should be tried twice.

To run each test, simply move your mouse over each grey box.

Simple Custom Cursor

For this test, we will simply show a custom cursor.


Firefox 2, 3.6, 8, 14, 18Works!
Chrome 21, 24, 25Works!
Safari 4.0.5, 5.1.4, 6.0.2Works!
IE 9, 10Works!
IE 6, 7, 8Works, but cursor is constrained to 32x32
Opera 12.14Fails - Custom cursors are not supported

Ok, not the end of the world. If we forget about Opera and restrict our cursor size to 32x32 for IE, we can support almost all browsers.

UPDATE 2-14-2013: Opera has decided to switch to WebKit for their rendering engine. This means we will likely see custom cursor support in the next WebKit based version of Opera!

Automatic Cursor Changing

This test will automatically alternate between two different cursors.


Firefox 2, 8, 14, 18Works!
Chrome 21, 24, 25Works!
Safari 5.1.4, 6.0.2Works!
Safari 4.0.5Fails* - Never changes after the first custom cursor
IE 7, 8, 9, 10Fails* - Never changes after the first custom cursor
IE 6Fails* - Changes to default arrow on first switch and remains that
Opera 12.14Fails - Custom cursors are not supported

Fails* - If you continually move the mouse around, then the cursor changes correctly.

Basically, mouse movement is required in many browsers in order to re-draw the correct custom cursor.

There is an open issue for Chrome about this: Issue #26723
However my tests with Chrome didn't show a problem.

Change Cursor on Mouse Down

Let's try changing the custom cursor when the mouse button is pushed down.


Firefox 2, 8, 14, 18Works!
Chrome 21, 24, 25Fails - Does not change on mouse down
Safari 4.0.5, Safari 5.1.4, 6.0.2Fails - Does not change on mouse down
IE 9, 10Fails - Does not change until mouse up, then shows the default arrow
IE 7, 8Fails* - Does not change until mouse up, then shows the down version
IE 6Fails* - Changes to default arrow on mouse down
Opera 12.14Fails - Custom cursors are not supported

Fails* - For IE 8 or less, if you move the mouse around, the cursor changes correctly.

This is where things start to get ugly. The ONLY browser that supports changing the cursor when the mouse button is pressed is FireFox.

So if you were hoping to have a cursor change while the user clicks on things... think again.

UPDATE 2-14-2013: A patch has landed on WebKit that fixes the bug that prevented the cursor from changing on mouse down.
This means future versions of Chrome and Safari should both support this feature soon!

Custom Cursor With Scroll Bar

Does the custom cursor work when using a scroll bar?


Firefox 2, 8, 14, 18Fails - Changes to default arrow when over scroll bar
Chrome 21, 24, 25Works!
Safari 4.0.5, Safari 5.1.4, 6.0.2Works!
IE 6, 7, 8, 9, 10Fails - Changes to default arrow when over scroll bar
Opera 12.14Fails - Custom cursors are not supported

Pretty poor support for this. Oddly enough, Chrome and Safari (WebKit) are the winners in this test.
While not tested, my guess is select boxes will show similar problems with custom cursors.


As you can see, ALL the browsers have a long ways to go before you can rely on custom cursor support for something like a game.

I discovered these problems when developing my latest web game: World of Card Games

As a work around, I use a transparent 1x1 cursor and draw my own custom cursor image with an <img> tag.
On mouse move I use a CSS transform to translate the position of the <img> to the current cursor coordinates. This gives pretty good performance.

Future web games I create will be WebGL based and their cursors will be also drawn with WebGL and likely animated.

I don't anticipate browser support improving any time soon. Many of these issues have been known about for years.

UPDATE 2-14-2013: With Opera switching to WebKit and a patch landing in WebKit to fix the on mouse down bug, looks like things may be improving a lot sooner than I first thought!