Skip to content

Instantly share code, notes, and snippets.

View mdakin's full-sized avatar

mdakin mdakin

  • Google
  • Zurich, Switzerland
View GitHub Profile
@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: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;
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: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);
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)
// 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);
// 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');
@mdakin
mdakin / gist:1e84b4eeb2e5e5aec33fd5d809f4ced2
Created September 10, 2017 23:36
Benchmark results for antlr4 lexer on input with non ascii characters Base versus special <Uint,DFAState> hash map.
Benchmark system:
Ryzen 1700+ 3.4Ghz, 32GB Ram, 1 TB Samsung 960 Evo NVMe
Input Text: ~50MB Turkish text from a news site,
Total chars: 45,430,066 Ascii: 41,465,690
Ascii Percent: 91.27%
Base Antlr (128 slot static lookup table, slow path for rest)
Total tokens:12103250
Total time: 13741ms.
package foo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
/**
* A map like structure that has unsigned integer keys and T values.
*
package foo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
/**
* A map like structure that has unsigned integer keys and T values.
*