Skip to content

Instantly share code, notes, and snippets.

View munificent's full-sized avatar

Bob Nystrom munificent

View GitHub Profile
@munificent
munificent / gist:7912965
Created December 11, 2013 15:58
Patch for generating default constructors at compile time. For mysterious reasons, it causes the method_call benchmark perf to degrade by ~10%.
diff --git a/src/wren_compiler.c b/src/wren_compiler.c
index cbb9ca6..83420f1 100644
--- a/src/wren_compiler.c
+++ b/src/wren_compiler.c
@@ -1600,6 +1600,24 @@ void block(Compiler* compiler)
emit(compiler, CODE_POP);
}
+// Defines a default constructor method with an empty body.
+static void defaultConstructor(Compiler* compiler)
@munificent
munificent / gist:7833535
Created December 6, 2013 22:52
Here's some stats on pub (pub.dartlang.org), which is the package manager for the Dart programming language (dartlang.org).
I downloaded the most recent versions of every package on pub a few weeks ago.
Then I ran cloc on them. Here's the stats:
packages: 558
.dart files: 9,519
comment lines: 215,179
blank lines: 279,407
code lines: 1,028,710
total: 1,523,296
@munificent
munificent / gist:7392306
Created November 10, 2013 01:11
An artificial benchmark to get a feel for how much memory layout and data cache misses affect the performance of a typical game loop. I found the numbers pretty astonishing, but I'd definitely appreciate feedback on if I did a decent job on the benchmark here. Try it, tweak it, and tell me what you think. Don't forget to run it in release mode!
#include <stdlib.h>
#include <time.h>
// This tests a simulated game loop with a bunch of different memory
// configurations. You have a bunch of actors. Each actor has a few components.
// Each frame every component for every actor is updated. Except for "wrong
// order", all components of the same "type" are update for each actor.
// In other words, it updates component #1 for every actor, then component #2,
// etc.
//
@munificent
munificent / gist:6942575
Created October 11, 2013 21:50
My solution to http://cslibrary.stanford.edu/109/TreeListRecursion.html. I think mine is more efficient than Nick's.
// This is a Dart solution to:
//
// Nick Parlante's "Great Tree-List Recursion Problem"
// http://cslibrary.stanford.edu/109/TreeListRecursion.html
//
// Before you read the code here, try to solve it youself first!
main() {
var tree = makeTree(100);
printTree(tree);
@munificent
munificent / gist:6136198
Created August 1, 2013 23:15
For kicks, I scraped Github's language pages and sorted them by rank
#1 JavaScript
#2 Ruby
#3 Java
#4 Shell
#5 Python
#6 PHP
#7 C
#8 C++
#9 Perl
#10 CoffeeScript
@munificent
munificent / gist:6136197
Created August 1, 2013 23:14
For kicks, I scraped Github's language pages and sorted them by rank
#1 JavaScript
#2 Ruby
#3 Java
#4 Shell
#5 Python
#6 PHP
#7 C
#8 C++
#9 Perl
#10 CoffeeScript
@munificent
munificent / gist:5328982
Created April 7, 2013 04:12
Beer-battered tilapia!
Ingredients:
- 5-6 tilapia fillets, cut in half lengthwise
- 1 cup flour, plus more for dredging
- 2 tsp salt (maybe a bit more)
- 2 tsp garlic powder
- 2 tsp onion powder
- 2 tsp black pepper
- 1 tbsp paprika
- dash cayenne
@munificent
munificent / stress.dart
Created March 19, 2013 20:31
This is my little script for stress-testing a Dart program. Change `script_to_run.dart` to the name of the Dart script to run. Make sure that script ends with a non-zero exit code to indicate failure.
import 'dart:io';
const MAX_ATTEMPTS = 10000;
const MAX_JOBS = 20;
var total = 0;
var numRunning = 0;
main() {
for (var i = 0; i < MAX_JOBS; i++) spawnProc();
class Graph {
num nodesNumber;
List<List<num>> edges;
Graph(this.nodesNumber, List<List<num>> edges) {
this.edges = new Iterable.generate(nodesNumber,
(_) => new List.fixedLength(nodesNumber)).toList();
for (var e in edges) edge(e[0], e[1], e[2]);
}
name: your_awesome_app
dependencies:
git: /home/daw/myLib # Or whatever the path to myLib is