Page MenuHomePhabricator

regexp_speed_comparison.js

Authored By
bzimport
Nov 21 2014, 10:23 PM
Size
820 B
Referenced Files
None
Subscribers
None

regexp_speed_comparison.js

var itm = '100,000,000 this is not a number'
var startTime = new Date()
for (var i = 0; i < 100000; i++)
{
// method 1
// if (itm.match(/^[+-]?[\d,]+(\.[\d,]*)?([eE][+-]?[\d,]+)?\%?$/) || itm.match(/^[+-]?\.[\d,]+([eE][+-]?[\d,]+)?\%?$/) || itm.match(/^0x[\da-f]+$/i))
// var three = 2 + 1
// method 2
if (itm.match(/^[+-]?[\d,]+(?:\.[\d,]*)?(?:[eE][+-]?[\d,]+)?\%?$/)
|| itm.match(/^[+-]?\.[\d,]+(?:[eE][+-]?[\d,]+)?\%?$/)
|| itm.match(/^0x[\da-f]+$/i))
var three = 2 + 1
//method 3
// if (itm.match(/^[+-]?(?:\d{1,3}(?:\,\d{3})*)*\.?\d*(?:[eE][+-]?\d+(?:\,\d{3})*)?[%\u00b0\u00bc\u00bd\u00be]?$/) && !itm.match(/^[eE]/))
// var three = 2 + 1
}
var endTime = new Date()
//replace "WScript.echo" with "alert" or whatever you need to display the results
WScript.echo(endTime - startTime)

File Metadata

Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4801
Default Alt Text
regexp_speed_comparison.js (820 B)

Event Timeline