Skip to content

Instantly share code, notes, and snippets.

View mraleph's full-sized avatar
🐌

Slava Egorov mraleph

🐌
View GitHub Profile
<div id="result"></div>
import 'dart:mirrors';
class Proxy {
static final getName = currentMirrorSystem().getName;
final target;
Proxy(this.target);
noSuchMethod(invocation) {
function Clash(x) {
// Each instance of Clash gets a different getter for the property
// xx. This for the second instance makes it impossible to have this
// accessor promoted to the hidden class because it does not match expected
// accessor (the same as the first instance had) which in turn prevents its
// inlining later.
Object.defineProperty(this, "xx", {
get: function () { return x * x }
});
}
@mraleph
mraleph / test.js
Last active August 29, 2015 14:18
function bar(x) {
try { // just to prevent inlining
return x;
} catch (e) { }
}
function foo(o) {
var sum = 0;
for (var i = 0; i < 10; i++) {
sum += bar(o.x); /* o.x will not be hoisted out of the loop */
--- FUNCTION SOURCE () id{0,0} ---
var iterations = 2;
print("Running (" + iterations + ")... ");
var testData = new Uint8Array(1024 * 1024);
for (var i = 0; i < 1024 * 1024; i++) {
testData[i] = i % 256;
}
var key = [0x80]; for (i = 1; i < 32; i++) key[i] = 0x07;
var nonce = []; for (i = 0; i < 8; i++) nonce[i] = 0x01;
if (iterations < 100) {
This file has been truncated, but you can view the full file.
--- FUNCTION SOURCE () id{0,0} ---
var iterations = 2;
print("Running (" + iterations + ")... ");
var testData = new Uint8Array(1024 * 1024);
for (var i = 0; i < 1024 * 1024; i++) {
testData[i] = i % 256;
}
var key = [0x80]; for (i = 1; i < 32; i++) key[i] = 0x07;
var nonce = []; for (i = 0; i < 8; i++) nonce[i] = 0x01;
if (iterations < 100) {
@mraleph
mraleph / y0.js
Created May 20, 2015 20:40
Strange performance affects from wrapping try/catch into a function
// ../jsshell-35.0/js y0.js
// TryCatch x 2,139,927 ops/sec ±0.96% (65 runs sampled)
// FastTry x 2,079,778 ops/sec ±1.07% (63 runs sampled)
// Fastest is TryCatch
load("lodash.js");
load("benchmark.js");
function fastTry (fn) {
#define LIST(V) \
V(A) \
V(B) \
V(C)
enum ListOfMyFavoriteEnglishLetters {
#define F(name) k##name,
LIST(F)
#undef F
After Optimizations
==== file:///usr/local/google/home/vegorov/Downloads/benchmark_mirrors.dart_::_testWithoutMirrors
0: B0[graph]:2 {
v0 <- Constant(#null) T{Null?}
v1 <- Constant(#<optimized out>)
v2 <- Constant(#Context@0x7f6422ac3461 num_variables: 0) T{Context}
v3 <- Parameter(0)
v4 <- Constant(#TypeArguments: [Type: class 'int']) T{TypeArguments}
v5 <- Constant(#1) [1, 1] T{_Smi}
v12 <- Constant(#true) T{bool}
@mraleph
mraleph / dump.lua
Last active September 30, 2015 15:34
local level = 2
while true do
local info = debug.getinfo (level)
if not info then break end
p(string.format("-- #%d | [%s] function %s at %s:%d (defined at %d)", level, tostring(info.func), info.name or "?", info.source or "", info.currentline or -1, info.linedefined or -1))
local localIdx = 1
while true do
local name, value = debug.getlocal(level, localIdx)