about summary refs log tree commit diff stats
path: root/prototypes
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-07-08 22:09:59 -0700
committerKartik Agaram <vc@akkartik.com>2020-07-08 22:14:42 -0700
commitf16f5690600ea74f2d77b72bf9167cf3a74c1d2e (patch)
treea63c61f6eba005f0e529e1c28e247cf7f2b92942 /prototypes
parent3ae9d0ed54f7cd13a1672d0f5ae29d3f9baf4027 (diff)
downloadmu-f16f5690600ea74f2d77b72bf9167cf3a74c1d2e.tar.gz
6622 - new syscalls: time and ntime
As a side-effect I find that my Linode can print ~100k chars/s. At 50 rows
and 200 columns per screen, it's 10 frames/s.
Diffstat (limited to 'prototypes')
-rw-r--r--prototypes/tile/2.mu1
-rw-r--r--prototypes/tile/3.mu75
2 files changed, 75 insertions, 1 deletions
diff --git a/prototypes/tile/2.mu b/prototypes/tile/2.mu
index 1d399c2b..41c19d74 100644
--- a/prototypes/tile/2.mu
+++ b/prototypes/tile/2.mu
@@ -42,7 +42,6 @@ fn main -> exit-status/ebx: int {
 
 fn render f: (addr buffered-file), start-row: int, num-rows: int {
   var num-cols/ecx: int <- copy 0xb9  # 185
-  rewind-stream f
   # if necessary, clear the row above
 $render:clear-loop: {
     compare start-row, 1
diff --git a/prototypes/tile/3.mu b/prototypes/tile/3.mu
new file mode 100644
index 00000000..3ee274de
--- /dev/null
+++ b/prototypes/tile/3.mu
@@ -0,0 +1,75 @@
+# benchmark: how fast can we print characters to screen?
+#
+# Requires a large file called "x" containing just ascii characters. One way
+# to generate it:
+#   cat /dev/urandom |base64 - |head -n 10000 > x
+# then merge pairs of lines.
+
+fn main -> exit-status/ebx: int {
+  var num-lines/ecx: int <- copy 0x64  # 100
+  clear-screen
+  # open a file
+  var f: (addr buffered-file)
+  {
+    var f-handle: (handle buffered-file)
+    var f-in/eax: (addr handle buffered-file) <- address f-handle
+    open "x", 0, f-in  # for reading
+    var f-out/eax: (addr buffered-file) <- lookup f-handle
+    copy-to f, f-out
+  }
+  # initial time
+  var t1_/eax: int <- time
+  var t1/edx: int <- copy t1_
+  # main loop
+  var iter/eax: int <- copy 1
+  {
+    compare iter, 0x640  # 1600
+    break-if->
+    render f, num-lines
+    iter <- increment
+    loop
+  }
+  # final time
+  var t2_/eax: int <- time
+  var t2/ebx: int <- copy t2_
+  # time taken
+  var t3/esi: int <- copy t2
+  t3 <- subtract t1
+  # clean up
+  clear-screen
+  # results
+  print-int32-hex-to-screen t1
+  print-string-to-screen "\n"
+  print-int32-hex-to-screen t2
+  print-string-to-screen "\n"
+  print-int32-hex-to-screen t3
+  print-string-to-screen "\n"
+  #
+  exit-status <- copy 0
+}
+
+fn render f: (addr buffered-file), num-rows: int {
+  var num-cols/ecx: int <- copy 0x64  # 100
+  # render screen
+  var row/edx: int <- copy 1
+  var col/ebx: int <- copy 1
+  move-cursor-on-screen row, col
+$render:render-loop: {
+    compare row, num-rows
+    break-if->=
+    var c/eax: byte <- read-byte-buffered f
+    compare c, 0xffffffff  # EOF marker
+    break-if-=
+    compare c, 0xa  # newline
+    {
+      break-if-!=
+      row <- increment
+      col <- copy 0
+      move-cursor-on-screen row, col
+      loop $render:render-loop
+    }
+    print-byte-to-screen c
+    col <- increment
+    loop
+  }
+}
oid'>51530916 ^
6a9d8191 ^


5f05e954 ^
51530916 ^


1ba81b0f ^
5f05e954 ^
6a9d8191 ^
5f05e954 ^


1ba81b0f ^
51530916 ^


be16deb0 ^
b39ceb27 ^
26785f2a ^
b39ceb27 ^
8f249677 ^
b39ceb27 ^

51530916 ^


4ea9905f ^


455f0338 ^

385ff136 ^
455f0338 ^



51530916 ^



fb4836dc ^


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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140