multiline

JavaScript performance comparison

Test case created by Sindre Sorhus

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  /*!
  	multiline
  	Multiline strings in JavaScript
  	https://github.com/sindresorhus/multiline
  	by Sindre Sorhus
  	MIT License
  */
  (function () {

  	'use strict';
  
  	// start matching after: comment start block => optional whitespace => newline
  	// stop matching before: last newline => optional whitespace => comment end block
  	var reCommentContents = /\/\*\s*(?:\r\n|\n)([\s\S]*?)(?:\r\n|\n)\s*\*\//;
  
  	var multiline = function (fn) {
  		if (typeof fn !== 'function') {
  			throw new TypeError('Expected a function.');
  		}
  
  		return reCommentContents.exec(fn.toString())[1];
  	};
  
  	if (typeof module !== 'undefined' && module.exports) {
  		module.exports = multiline;
  	} else {
  		window.multiline = multiline;
  	}
  })();

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
multiline
var str = multiline(function(){/*
<!doctype html>
<html>
	<body>
		<h1>Hello world</h1>
	</body>
</html>
*/});
pending…
string concat
var str = '' +
'<!doctype html>' +
'<html>' +
'	<body>' +
'		<h1>Hello world</h1>' +
'	</body>' +
'</html>' +
'';
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.

0 Comments