Skip to content

Instantly share code, notes, and snippets.

enum ValueType
{
NULL,
UNDEFINED,
NUMBER_INT,
NUMBER_DOUBLE,
STRING,
/*
This test detects if engine cache bytecode or not.
*/
var _main = function()
{
var bigCode = String(_main);
bigCode = bigCode.slice(bigCode.indexOf('{') + 1, bigCode.lastIndexOf('}'));
bigCode = new Array(11).join(bigCode); // *= 10 to make really big code
// http://en.wikipedia.org/wiki/Fast_inverse_square_root
/*
Discovering old well known algorithm speed in js.
*/
/*
Update 1
Added 3rd variant - 1st with removed <y> varable. Hm, it really become more faster. Thanks Andrea!
*/
/*
Strong implementation must check that key is object,
hide weakMapN_ from enumeration, make it externally readonly and non deletable(Object.defineProperty, if presents),
but its bad for performance.
*/
(function($G)
{
var nextStoreKeyId = 0;
/*
es5 introduces new Object api. Object.keys returns array of own enumerable keys of object.
In es3 we have classic construction "for in hasOwnProperty" for this purposes.
Test try to find what is best - es3 enumeration or es5
In es5 we have overhead of array making and allocation
In es3 we have overhead of enumeration extra properties from prototype chain and filter it(using hasOwnProperty - extra function call)
update 1
according brilliant idea of @abozhilov (http://twitter.com/abozhilov/status/26758011447) there is 3rd way which
uses nonstandard __proto__ (presents in v8 and JagerMonkey)
$jb._isFunction([].map) &&
(function(){
var n = 0
, isFail = false
, a = [1, 2, 3]
, b = a.map(
function(v, i, vs)
{
n |= 1 << i;
Array.prototype._shuffleSelf = function()
{
var i = this.length;
if(i >= 2)
{
var _rand = Math.random;
while(--i)
{
// via me and @kangax
(function()
{
var a = {};
var someId = new Date();
var proto = {};
proto[someId] = someId;
return (a.__proto__ = proto, a[someId] === someId) &&
@bga
bga / ieemu.js
Last active August 25, 2020 17:10
/*
Copyright 2006 Emil A Eklund <[email protected]> & Erik Arvidsson <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
/*
this test shows independence loop structure of performance
internal asm code become same
*/
var m = 1000
, aL = new Array(m)
;
aL[aL.length - 1] = 1;