-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathtest.nim
More file actions
47 lines (39 loc) · 993 Bytes
/
test.nim
File metadata and controls
47 lines (39 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import base64, times, strutils, strformat
import net
import posix
let STR_SIZE = 131072
let TRIES = 8192
let str = strutils.repeat('a', STR_SIZE)
proc notify(msg: string) =
try:
var socket = newSocket()
defer: socket.close()
socket.connect("localhost", Port(9001))
socket.send(msg)
except:
discard
var compiler = "Nim Clang"
when defined(gcc):
compiler = "Nim GCC"
notify(&"{compiler}\t{getpid()}")
var t = times.epochTime()
var i = 0
var s:int64 = 0
var str2 = base64.encode(str)
stdout.write(fmt"encode {str[..3]}... to {str2[..3]}...: ")
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)}")
notify("stop")