Skip to content

Instantly share code, notes, and snippets.

View mraleph's full-sized avatar
🐌

Slava Egorov mraleph

🐌
View GitHub Profile
--- 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 / 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 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 }
});
}
import 'dart:mirrors';
class Proxy {
static final getName = currentMirrorSystem().getName;
final target;
Proxy(this.target);
noSuchMethod(invocation) {
<div id="result"></div>
$ node -e "console.log(process.versions.v8)"
3.14.5.9
$ node bubble.js
81754
$ iojs -e "console.log(process.versions.v8)"
4.1.0.7
$ iojs bubble.js
42165
$ diff -u bubble.js bubble1.js
--- bubble.js 2015-03-04 20:41:08.432717779 +0100
function f(x, y) {
x = 'Q: why?';
console.log(arguments[0]);
arguments[1] = 'A: just because';
console.log(y);
}
f(null, null);
// Q: why?
// A: just because
// Benefit of optimizing this function via OSR is high:
// a) it is long running;
// b) optimization speeds up the code considerably;
// c) it is called a few times only.
function loopy() {
var arr = new Uint8Array(100);
for (var j = arr[0]; j < 1e2; j++) {
for (var i = arr[0]; i < 1e6; i++) {
Math.sqrt(arr[0] * arr[0]);
}
@mraleph
mraleph / writer.dart
Last active May 5, 2025 14:00
manual big endian conversion in Dart
library writer;
import 'dart:typed_data';
/// Writer wraps a fixed size Uint8List and writes values into it using
/// big-endian byte order.
class Writer {
/// Output buffer.
final Uint8List out;
@mraleph
mraleph / test.cc
Last active August 29, 2015 14:08
#include <cstdio>
#include <stdint.h>
struct value_t {
union {
float fx[2];
int32_t ix[2];
};