Skip to content

Instantly share code, notes, and snippets.

@aantron
aantron / measure.ml
Created December 3, 2016 13:16
Profiling Markup.ml
(* ocamlfind opt -linkpkg -package unix -package markup measure.ml *)
let measure f =
let open Unix in
let start_times = times () in
let start_wall = gettimeofday () in
f ();
(* ocamlfind opt -linkpkg -package lwt.ppx -package lwt.unix -package mtime.os timing.ml && ./a.out *)
open Lwt.Infix
let f1 dir =
let s = Lwt_unix.files_of_directory dir in
let s = Lwt_stream.filter (fun s -> s <> "." && s <> "..") s in
let s = Lwt_stream.map (Filename.concat dir) s in
Lwt_stream.to_list s
@aantron
aantron / writev.c
Created November 19, 2016 22:12
Lwt_unix.writev performance measurements
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/times.h>
@aantron
aantron / take.ml
Last active March 15, 2016 22:24
let take limit html =
let spaces = Str.regexp "[ \t\r\n]+" in
let rec repeat acc n v = if n > 0 then repeat (v::acc) (n - 1) v else acc in
let filter_signals =
(0, 0)
|> Markup.transform (fun ((seen, unclosed_elements) as state) signal ->
match signal with
| `Text ss ->