Multiple vs Singular Delimited Data Attributes

JavaScript performance comparison

Test case created by Josh Dean

Preparation code

<a href="#" class="trackevent" data-category="Video" data-action="Play" data-label="Name" data-value="SALT">Track Event</a>
<a href="#" data-trackevent="Video;;Play;;Name;;SALT">Track Event</a>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Multiple Attributes
var $this = jQuery('a.trackevent');
var category = $this.data('category');
var action = $this.data('action');
var label = $this.data('label');
var value = $this.data('value');
pending…
Single Delimited Attribute
var $this = jQuery('[data-trackevent]');
var data = $this.data('trackevent').split(';;');
var category = data[0];
var action = data[0];
var label = data[0];
var value = data[0];
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment