This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const protobuf = require('protobufjs') | |
const protoFileName = process.argv[2] | |
if (protoFileName == null || !fs.existsSync(protoFileName)) { | |
console.error(`USAGE: ${process.argv[0]} <schema-file.proto>`) | |
process.exit(-1) | |
} | |
protobuf.load(protoFileName, function (err, root) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Methodology: | |
1. The benchmark repeatedly performs every operation 2.5k times on randomly created and initialised objects | |
2. I ran the benchmark 5 times, obtaining 5 samples of 2.5k points for every operation | |
3. All the averages, means and standrad deviations that you see are actually median of means, median of medians and median of | |
standard deviations. | |
4. All IDs are incremented natural numbers (not recommended by datastore but somewhat reflects our usage of it) | |
5. I could not perform the `query` operation, because datastore now explicity asks to create an index for custom fields | |
(they changed the old behaviour where index was created automatically) and unfortunately I don't have permissions for that. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% node pub.js <num-messages-to-send> <rate-limit-ms> | |
# EXAMPLE: node pub.json 1500 100 (will send 1500 messages, rate limit: at most 1msg every 100ms) | |
% node sub.js 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run all commands in different terminal sessions | |
% node sub.js 1 | |
% node sub.js 2 | |
% node sub.js 3 | |
% node pub.js 100 | |
<no out-of-order messages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
MOD = 10 ** 9 + 7 | |
MAX_N = 8191 | |
NBASE = 3500 | |
UNIQUE_NUMS = 1000 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collection; | |
import java.util.HashMap; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.Queue; | |
import java.util.Scanner; | |
public class FoolsAndRoads { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from math import log | |
def calc_entropy(distribution): | |
num_chars = sum([count for count in distribution.values()]) | |
ent = 0 | |
for (c, count) in distribution.items(): | |
p = count / num_chars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
#include <cstring> | |
struct sa_node { | |
std::pair<int, int> bounds; | |
int idx; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
isSquare :: Int -> Bool | |
isSquare n = sr * sr == n | |
where sr = floor .sqrt . fromIntegral $ n | |
trySequence :: Int -> [Int] -> [[Int]] | |
trySequence x [] = [[x]] | |
trySequence x seq = map (x :) $ foldr step [] seq | |
where step a acc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import System.Environment | |
import System.Exit | |
import System.Random | |
import Control.Monad | |
import Control.Concurrent | |
import Control.Concurrent.MVar | |
workerFn :: Int -> Int -> MVar Double -> IO () |
NewerOlder