summaryrefslogtreecommitdiff
path: root/080_blog/00040_Haskell/00065_Base64-Encoder
diff options
context:
space:
mode:
Diffstat (limited to '080_blog/00040_Haskell/00065_Base64-Encoder')
-rw-r--r--080_blog/00040_Haskell/00065_Base64-Encoder/base64.cast314
-rw-r--r--080_blog/00040_Haskell/00065_Base64-Encoder/index.md16
2 files changed, 119 insertions, 211 deletions
diff --git a/080_blog/00040_Haskell/00065_Base64-Encoder/base64.cast b/080_blog/00040_Haskell/00065_Base64-Encoder/base64.cast
index 63fece1..54f3ab5 100644
--- a/080_blog/00040_Haskell/00065_Base64-Encoder/base64.cast
+++ b/080_blog/00040_Haskell/00065_Base64-Encoder/base64.cast
@@ -1,322 +1,226 @@
{
- "duration": 14.820928,
+ "command": null,
+ "width": 101,
"title": null,
+ "height": 6,
"env": {
"SHELL": "/bin/bash",
"TERM": "screen-256color"
},
- "width": 106,
"stdout": [
[
- 0.019966,
- "miguel@megaloman:~$ "
- ],
- [
- 1.524665,
- "t"
- ],
- [
- 0.08111,
- "h"
- ],
- [
- 0.095838,
- "i"
- ],
- [
- 0.118019,
- "s"
- ],
- [
- 0.086883,
- " "
- ],
- [
- 0.089573,
- "i"
- ],
- [
- 0.134283,
- "s"
- ],
- [
- 0.096031,
- " "
- ],
- [
- 0.114016,
- "a"
- ],
- [
- 0.166151,
- " "
- ],
- [
- 0.319094,
- "l"
- ],
- [
- 0.195916,
- "o"
- ],
- [
- 0.142042,
- "c"
+ 0.020042,
+ "miguel@megaloman:~/git/haskell/base64$ "
],
[
- 0.139961,
- "a"
+ 0.972847,
+ "cat /dev/urandom | pv | ./base64 > /dev/null "
],
[
- 0.07801,
- "l"
+ 0.43902,
+ "\r\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[1Pecho \"Welcome to Base64 encoding\" | ./base64"
],
[
- 0.081012,
- " "
- ],
- [
- 0.094941,
- "a"
- ],
- [
- 0.120898,
- "s"
- ],
- [
- 0.107959,
- "c"
- ],
- [
- 0.115993,
- "i"
- ],
- [
- 0.137871,
- "i"
+ 0.83889,
+ "\r\n"
],
[
- 0.205335,
- "n"
+ 0.001251,
+ "V2VsY29tZSB0byBCYXNlNjQgZW5jb2RpbmcK\r\n"
],
[
- 0.108673,
- "e"
+ 0.000356,
+ "miguel@megaloman:~/git/haskell/base64$ "
],
[
- 0.127436,
- "m"
+ 1.151505,
+ "echo \"Welcome to Base64 encoding\" | ./base64"
],
[
- 0.123916,
- "a"
+ 0.328933,
+ "\r\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[Ccat /dev/urandom | pv | ./base64 > /dev/null "
],
[
- 0.244565,
+ 0.833,
"\r\n"
],
[
- 0.000482,
- "bash: this: command not found\r\n"
+ 1.001665,
+ " 253MiB 0:00:01 [ 253MiB/s] [ <=> ]\r"
],
[
- 0.000346,
- "miguel@megaloman:~$ "
+ 0.999837,
+ " 500MiB 0:00:02 [ 247MiB/s] [ <=> ]\r"
],
[
- 1.012884,
- "this is a local asciinema"
+ 1.000048,
+ " 753MiB 0:00:03 [ 252MiB/s] [ <=> ]\r"
],
[
- 0.230737,
- "\r\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C"
+ 1.000117,
+ "1001MiB 0:00:04 [ 247MiB/s] [ <=> ]\r"
],
[
- 0.140235,
- "\u001b[1@e"
+ 0.999649,
+ "1.22GiB 0:00:05 [ 251MiB/s] [ <=> ]\r"
],
[
- 0.097927,
- "\u001b[1@c"
+ 1.000026,
+ "1.47GiB 0:00:06 [ 250MiB/s] [ <=> ]\r"
],
[
- 0.188824,
- "\u001b[1@j"
+ 1.000236,
+ "1.72GiB 0:00:07 [ 253MiB/s] [ <=> ]\r"
],
[
- 0.000974,
- "\u001b[1@o"
+ 1.000056,
+ "1.96GiB 0:00:08 [ 252MiB/s] [ <=> ]\r"
],
[
- 0.421424,
- "\b\u001b[1P"
+ 0.999645,
+ " 2.2GiB 0:00:09 [ 244MiB/s] [ <=> ]\r"
],
[
- 0.117902,
- "\b\u001b[1P"
+ 1.000274,
+ "2.45GiB 0:00:10 [ 253MiB/s] [ <=> ]\r"
],
[
- 0.208192,
- "\u001b[1@h"
+ 0.999751,
+ "2.69GiB 0:00:11 [ 244MiB/s] [ <=> ]\r"
],
[
- 0.115112,
- "\u001b[1@ "
+ 1.000191,
+ "2.93GiB 0:00:12 [ 252MiB/s] [ <=> ]\r"
],
[
- 0.012814,
- "\u001b[1@o"
+ 0.999772,
+ "3.18GiB 0:00:13 [ 248MiB/s] [ <=> ]\r"
],
[
- 0.295287,
- "\r\n"
+ 1.000312,
+ "3.43GiB 0:00:14 [ 257MiB/s] [ <=> ]\r"
],
[
- 0.000755,
- "bash: ech: command not found\r\n"
+ 0.999856,
+ "3.68GiB 0:00:15 [ 254MiB/s] [ <=> ]\r"
],
[
- 0.000509,
- "miguel@megaloman:~$ "
+ 1.000239,
+ "3.93GiB 0:00:16 [ 253MiB/s] [ <=> ]\r"
],
[
- 0.480858,
- "ech othis is a local asciinema"
+ 0.99986,
+ "4.17GiB 0:00:17 [ 248MiB/s] [ <=> ]\r"
],
[
- 0.192018,
- "\r\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C"
+ 0.999739,
+ " 4.4GiB 0:00:18 [ 242MiB/s] [ <=> ]\r"
],
[
- 0.237975,
- "\u001b[C"
+ 1.000023,
+ "4.65GiB 0:00:19 [ 252MiB/s] [ <=> ]\r"
],
[
- 0.118994,
- "\u001b[C"
+ 1.000103,
+ "4.89GiB 0:00:20 [ 245MiB/s] [ <=> ]\r"
],
[
- 0.146091,
- "\u001b[1P"
+ 1.000106,
+ "5.14GiB 0:00:21 [ 255MiB/s] [ <=> ]\r"
],
[
- 0.348015,
- "\u001b[1P"
+ 1.000102,
+ "5.38GiB 0:00:22 [ 246MiB/s] [ <=> ]\r"
],
[
- 0.562446,
- "\u001b[1@h"
+ 1.000042,
+ "5.63GiB 0:00:23 [ 252MiB/s] [ <=> ]\r"
],
[
- 0.437804,
- "\u001b[C"
+ 0.999787,
+ "5.87GiB 0:00:24 [ 250MiB/s] [ <=> ]\r"
],
[
- 0.219332,
- "\u001b[1@ "
+ 1.000079,
+ "6.11GiB 0:00:25 [ 248MiB/s] [ <=> ]\r"
],
[
- 0.220637,
- "\r\n"
+ 1.000035,
+ "6.36GiB 0:00:26 [ 247MiB/s] [ <=> ]\r"
],
[
- 0.000486,
- "this is a local asciinema\r\n"
+ 0.999929,
+ " 6.6GiB 0:00:27 [ 250MiB/s] [ <=> ]\r"
],
[
- 0.000206,
- "miguel@megaloman:~$ "
+ 0.999966,
+ "6.84GiB 0:00:28 [ 244MiB/s] [ <=> ]\r"
],
[
- 1.218406,
- "m"
+ 1.000047,
+ "7.09GiB 0:00:29 [ 252MiB/s] [ <=> ]\r"
],
[
- 0.079499,
- "c"
+ 0.999829,
+ "7.33GiB 0:00:30 [ 250MiB/s] [ <=> ]\r"
],
[
- 0.170894,
- "\r\n"
+ 0.99996,
+ "7.57GiB 0:00:31 [ 245MiB/s] [ <=> ]\r"
],
[
- 0.00735,
- "\u001b[?1049h\u001b[?1h\u001b="
+ 1.000063,
+ "7.81GiB 0:00:32 [ 248MiB/s] [ <=> ]\r"
],
[
- 0.000586,
- "\u001b[1;9r\u001b[4l\u001b(B\u001b)0\u001b[9;1H\u001b[m\u000f\u001b[37m\u001b[40m\u001b[m\u000f\u001b[39;49m\r \r\u001b[?1l\u001b>\u001b[?1049l\u001b[?1049h\u001b[?1h\u001b="
+ 0.999947,
+ "8.06GiB 0:00:33 [ 251MiB/s] [ <=> ]\r"
],
[
- 0.021657,
- "\u001b[?1001s\u001b[?1002h\u001b[?1006h\u001b[?2004h"
+ 1.000249,
+ " 8.3GiB 0:00:34 [ 246MiB/s] [ <=> ]\r"
],
[
- 0.000429,
- "\u001b[1;9r\u001b[4l\u001b(B\u001b)0\u001b[?1h\u001b=\u001b[m\u000f\u001b[39m\u001b[49m\u001b[1;9r\u001b[H\u001b[J\u001b[2;105H\u001b[1K \u001b[37m\u001b[40m|\u001b[2;106H"
+ 1.000158,
+ "8.55GiB 0:00:35 [ 253MiB/s] [ <=> ]\r"
],
[
- 0.000193,
- "\b\u001b[39m\u001b[49m\u001b[1K \u001b[37m\u001b[40m╗\u001b[2;106H"
+ 0.999634,
+ "8.79GiB 0:00:36 [ 254MiB/s] [ <=> ]\r"
],
[
- 0.000114,
- "\b\u001b[39m\u001b[49m\u001b[1K \u001b[37m\u001b[40m/\u001b[2;106H"
+ 1.000289,
+ "9.04GiB 0:00:37 [ 251MiB/s] [ <=> ]\r"
],
[
- 0.000129,
- "\b\u001b[39m\u001b[49m\u001b[1K \u001b[37m\u001b[40m╗\u001b[2;106H"
+ 0.99977,
+ "9.29GiB 0:00:38 [ 251MiB/s] [ <=> ]\r"
],
[
- 0.000156,
- "\u001b]0;mc [miguel@megaloman]:~\u0007\u001b>"
+ 1.000013,
+ "9.53GiB 0:00:39 [ 248MiB/s] [ <=> ]\r"
],
[
- 0.000337,
- "\u001b[7;1H\u001b[39m\u001b[49mHint: Want your plain shell? Press C-o, and get back to MC with C-o again.\u001b[7;106H"
+ 1.000045,
+ "9.77GiB 0:00:40 [ 247MiB/s] [ <=> ]\r"
],
[
- 0.000251,
- "\u001b]0;mc [miguel@megaloman]:~\u0007\u001b>"
+ 0.999859,
+ " 10GiB 0:00:41 [ 248MiB/s] [ <=> ]\r"
],
[
- 0.000102,
- "\u001b[1;1H\u001b[30m\u001b[47m Left File Command Options Right \u001b[2;1H\u001b[37m\u001b[40m╔«═\u001b[97m\u001b[105m ~ \u001b[37m\u001b[40m═════════════════════════════════════════⋅[^]»╗╔«═ ~ ═════════════════════════════════════════⋅[^]»\r\n║\u001b[97m↑n Name \u001b[37m│\u001b[97m Size \u001b[37m│\u001b[97mModify time \u001b[37m║║\u001b[97m↑n Name \u001b[37m│\u001b[97m Size \u001b[37m│\u001b[97mModify time \u001b[37m║\u001b[4;1H╟───────────────────────────────────────────────────╢╟───────────────────────────────────────────────────╢\u001b[5;1H║UP--DIR ║║"
+ 0.760304,
+ "^C\r\n"
],
[
- 1e-05,
- "UP--DIR ║\u001b[6;1H╚═════════════════════════════════ 158G/234G (67%) ═╝╚═════════════════════════════════ 158G/234G (67%) ═╝\u001b[8;1H\u001b[39m\u001b[49mmiguel@megaloman:~$\u001b[84C\u001b[31m[^]\u001b[9;1H 1\u001b[97mHelp \u001b[31m 2\u001b[97mMenu \u001b[31m 3\u001b[97mView \u001b[31m 4\u001b[97mEdit \u001b[31m 5\u001b[97mCopy \u001b[31m 6\u001b[97mRenMov \u001b[31m 7\u001b[97mMkdir \u001b[31m 8\u001b[97mDelete \u001b[31m 9\u001b[97mPullDn \u001b[31m10\u001b[97mQuit \u001b[9;105H \b\u001b[4h \u001b[4l\u001b[8;21H"
- ],
- [
- 1.221371,
- "\u001b[1;1H\u001b[39m \u001b[2;1H \u001b[3;1H \u001b[4;1H \u001b[5;1H \u001b[6;1H \u001b[7;1H \u001b[8;1H \u001b[9;1H \u001b[1;106H\u001b[?2"
- ],
- [
- 4.5e-05,
- "004l\u001b[?1006l\u001b[?1002l\u001b[?1001r"
- ],
- [
- 0.000416,
- "\u001b[?1l\u001b>\u001b[9;1H\u001b[m\u000f\u001b[39;49m\r \r\u001b[?1l\u001b>\u001b[?1049l\u001b[39;49m"
- ],
- [
- 0.000319,
+ 0.000409,
"\r\n"
],
[
- 0.001118,
- "miguel@megaloman:~$ "
- ],
- [
- 0.791031,
- "e"
- ],
- [
- 0.62602,
- "\b\u001b[K"
+ 0.000128,
+ "miguel@megaloman:~/git/haskell/base64$ "
]
],
- "height": 9,
- "command": null,
- "version": 1
+ "version": 1,
+ "duration": 46.348438
} \ No newline at end of file
diff --git a/080_blog/00040_Haskell/00065_Base64-Encoder/index.md b/080_blog/00040_Haskell/00065_Base64-Encoder/index.md
index 0ede6cf..3fd87ee 100644
--- a/080_blog/00040_Haskell/00065_Base64-Encoder/index.md
+++ b/080_blog/00040_Haskell/00065_Base64-Encoder/index.md
@@ -2,18 +2,22 @@ Miguel's Base64 Encoder
=======================
February 19, 2018
-Coded on a winter afternoon to fully understand **base64 encoding** and play with
+Initially coded on a cold winter afternoon to fully understand **base64 encoding** and play with
**Haskell**, which is always an indisputable pleasure.
-Coded in _big anger_, due to Nick's fairy tales about saving his encrypted binary
-data in plain ASCII configuration files, featuring strange letters and
-non-printable characters. :P
+Coded in _big anger_, due to my friend Nick's fairy tales about saving his encrypted binary
+data in plain _ASCII_ configuration files, featuring strange letters and non-printable characters. :smile:
-<asciinema-player cols="106" rows="9" preload="true" theme="solarized-dark" autoplay="true" src="base64.cast"></asciinema-player>
+_EDIT_: After optimizing my naive implementation, the encoder now reaches speeds
+of around **240MB/s** on a single core of my _i7-4790K_.
+
+<asciinema-player loop="1" preload="true" theme="solarized-dark" autoplay="true" src="base64.cast"></asciinema-player>
+
+The source code below was auto-fetched from:
+<https://gitweb.softwarefools.com/?p=miguel/haskell.git;a=blob;f=base64/base64.hs>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.haskell .numberLines}
{BEGIN:EMBED}
https://gitweb.softwarefools.com/?p=miguel/haskell.git;a=blob_plain;f=base64/base64.hs
{END:EMBED}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The above code was auto-fetched from: <https://gitweb.softwarefools.com/?p=miguel/haskell.git;a=blob_plain;f=base64/base64.hs>