Skip to content

Instantly share code, notes, and snippets.

@rbnpercy
Created November 11, 2019 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbnpercy/d92146901842dc2273152f3103756c54 to your computer and use it in GitHub Desktop.
Save rbnpercy/d92146901842dc2273152f3103756c54 to your computer and use it in GitHub Desktop.
import base64, times, strutils, strformat
let STR_SIZE = 131072
let TRIES = 8192
let str = strutils.repeat('a', STR_SIZE)
var str2 = base64.encode(str)
stdout.write(fmt"encode {str[..3]}... to {str2[..3]}...: ")
var t = times.epochTime()
var i = 0
var s:int64 = 0
while i < TRIES:
str2 = base64.encode(str)
s += len(str2)
i += 1
echo(fmt"{s}, {formatFloat(times.epochTime() - t, ffDefault, 6)}")
var str3 = base64.decode(str2)
stdout.write(fmt"decode {str2[..3]}... to {str3[..3]}...: ")
t = times.epochTime()
i = 0
s = 0
while i < TRIES:
str3 = base64.decode(str2)
s += len(str3)
i += 1
echo(fmt"{s}, {formatFloat(times.epochTime() - t, ffDefault, 6)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment