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
FileReader fileReader = new FileReader("ten.json"); | |
BufferedReader bufReader = new BufferedReader(fileReader); | |
int lines = 0; | |
while (bufReader.readLine() != null) { | |
lines++; | |
} | |
System.out.println(lines); |
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
(reduce + | |
(pmap (fn [fname] | |
(with-open [rdr (io/reader fname)] | |
(count-lines rdr))) | |
["xaa" "xab" "xac" "xad"])) ;; 2.5gb JSON files |
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
(ns sunshine.widefinder | |
(:import (java.io BufferedInputStream InputStreamReader BufferedReader RandomAccessFile FileInputStream File))) | |
(defn chunk-file | |
"Partitions a file into n line-aligned chunks. Returns a list of start and | |
end byte offset pairs." | |
[filename n] | |
(with-open [file (RandomAccessFile. filename "r")] | |
(let [offsets (for [offset (range 0 (.length file) (/ (.length file) n))] | |
(do (when-not (zero? offset) |
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 <stdio.h> | |
#include <fcntl.h> | |
#include <err.h> | |
#include <unistd.h> | |
#include <inttypes.h> | |
#define BUF_SIZE (1048576 * 10) | |
int main(int argc, char *argv[]) | |
{ |
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
(with-open [file-stream (FileInputStream. ten-gb-filename)] | |
(let [channel (chan 500) | |
;; make four workers to read byte arrays off the channel: | |
counters (for [_ (range 4)] | |
(go-loop [newline-count 0] | |
(let [barray (async/<! channel)] | |
(if (nil? barray) ;; channel is closed | |
newline-count | |
(recur (+ newline-count | |
(count-newlines barray)))))))] |
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
(defn count-newlines [^bytes barray] | |
(let [num-bytes (alength barray)] | |
(loop [i 0 | |
newlines 0] | |
(if (>= i num-bytes) | |
newlines | |
(if (= 10 (aget ^bytes barray i)) | |
(recur (inc i) | |
(inc newlines)) | |
(recur (inc i) |
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
(ns sunshine.disk-read | |
(:require [clojure.core.async :as async :refer [>! <! go-loop chan close! <!!]]]) | |
(:import (java.io BufferedReader FileReader FileInputStream BufferedInputStream InputStreamReader))) | |
(def ten-gb-filename "ten.json") | |
(def one-meg (* 1024 1024)) | |
(defn ^FileInputStream input-stream [^String fname] | |
(FileInputStream. fname)) |
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
mdworker 20036 | |
DashlaneAgent 24287 | |
tmux 30025 | |
fish 36820 | |
WindowServer 43246 | |
dtrace 48262 | |
coreaudiod 48714 | |
hidd 86578 | |
iTerm2 102152 | |
Google Chrome He 365060 |
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
sudo dtrace -o syscalls_by_process.txt -n 'syscall:::entry { @num[execname] = count(); }' & | |
sleep 60*10 && jobs -p|tail -1|xargs sudo kill |