Skip to content

Instantly share code, notes, and snippets.

View mdakin's full-sized avatar

mdakin mdakin

  • Google
  • Zurich, Switzerland
View GitHub Profile
// Copyright (c) 2015, <your name>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
import 'dart:typed_data';
import 'dart:profiler';
const int MAX_ENTRIES=16;
UserTag linearSearchTag = new UserTag('Linear Search');
UserTag lookup = new UserTag('lookup');
// Copyright (c) 2015, <your name>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
import 'dart:typed_data';
const int MAX_ENTRIES=16;
class SmallMap {
var keys=new List(MAX_ENTRIES);
var hashCodes=new Int32List(MAX_ENTRIES);
Key (String) length: 5
sml map fill size: 1 time: 16 ms (8.0 ns/op)
std map fill size: 1 time: 33 ms (16.5 ns/op)
sml map look size: 1 time: 12 ms (6.0 ns/op)
std map look size: 1 time: 23 ms (11.5 ns/op)
sml map fill size: 2 time: 37 ms (9.25 ns/op)
std map fill size: 2 time: 56 ms (14.0 ns/op)
sml map look size: 2 time: 23 ms (5.75 ns/op)
@mdakin
mdakin / gist:9232849
Last active August 29, 2015 13:56
Approximate cos with simd
import "dart:typed_data";
import "dart:math";
class AMath {
final Float32x4 a = new Float32x4.splat(0.9999932946);
final Float32x4 b = new Float32x4.splat(-0.4999124376);
final Float32x4 c = new Float32x4.splat(0.0414877472);
final Float32x4 d = new Float32x4.splat(-0.0012712095);
import "dart:typed_data";
import "dart:math";
const int TABLE_SIZE = 1 << 10;
const double HALF_PI = PI / 2;
class ApproxMath {
Float64List _sine;
int tableSize;
double sinFactor;
@mdakin
mdakin / gist:9108434
Created February 20, 2014 07:10
Typed array performance 2
import "dart:typed_data";
import "dart:math";
void main() {
int rs = 1000000;
int iter = 50;
Float64List rnd = new Float64List(rs);
Random r = new Random(1);
for (int i = 0; i < rs; i++) {
rnd[i] = r.nextDouble() * PI;
@mdakin
mdakin / gist:9108423
Created February 20, 2014 07:09
Typed array performance 1
import "dart:typed_data";
import "dart:math";
void main() {
int rs = 1000000;
int iter = 50;
Float64List rnd = new Float64List(rs);
Random r = new Random(1);
for (int i = 0; i < rs; i++) {
rnd[i] = r.nextDouble() * PI;
@mdakin
mdakin / gist:9108419
Created February 20, 2014 07:09
Typed array performance 1
import "dart:typed_data";
import "dart:math";
void main() {
int rs = 1000000;
int iter = 50;
Float64List rnd = new Float64List(rs);
Random r = new Random(1);
for (int i = 0; i < rs; i++) {
rnd[i] = r.nextDouble() * PI;
@mdakin
mdakin / gist:5130420
Created March 10, 2013 21:07
dart base64 perf test.
import 'dart:math';
var random = new Random(0xCAFEBABE);
/// The base64 encoding table
final List<int>characters = const [
// A-Z [65-90]
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
// a-z [97-122]
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
@mdakin
mdakin / gist:4945570
Created February 13, 2013 15:51
Test app
package lexer;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.Token;
public class Test {
private static String testStr =
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy" +
" nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim " +