Skip to content

Commit 1b7b552

Browse files
committed
Feature(compiler): Use latest runtime with optimized Math.random
1 parent 4ed2b26 commit 1b7b552

4 files changed

Lines changed: 19 additions & 27 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ $ ./bin/ssc calculate-pi.ts
4747
Next run it:
4848

4949
```sh
50-
$ ./output/main
50+
$ time ./output/main
5151
```
5252

5353
This will produce:
5454

5555
```
56-
3.141560
56+
3.144800
57+
./output/main 0,01s user 0,00s system 80% cpu 0,013 total
5758
```
5859

5960
### LICENSE

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"commander": "^2.19.0"
2626
},
2727
"dependencies": {
28-
"@static-script/runtime": "^0.8.0",
28+
"@static-script/runtime": "^0.9.0",
2929
"llvm-node": "github:MichaReiser/llvm-node#master",
3030
"typescript": "^3.1.1"
3131
}

sandbox/do-simple-math.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11

22
{
3-
function doMath(): number {
4-
const a = 5.5;
5-
const b = 14.5;
3+
function calculatePI(cycles: number): number {
4+
let inside = 0;
65

7-
return ((a + b) * 50) / 10;
8-
}
9-
10-
const a: int8 = 10;
11-
const b: int16 = 10;
12-
const c: int32 = 10;
13-
const d: int64 = 10;
14-
const e: int128 = 10;
6+
for (let i = 0; i < cycles; i++) {
7+
let x = Math.random() * 2 - 1;
8+
let y = Math.random() * 2 - 1;
159

16-
console_log("hello");
17-
console_log(doMath());
18-
console_log(true);
19-
console_log(false);
20-
console_log(1 > 5);
21-
console_log(1 < 5);
10+
if ((x*x + y*y) < 1) {
11+
inside++
12+
}
13+
}
2214

23-
if (5 > 4) {
24-
console_log('5 > 4');
25-
} else {
26-
console_log('5 < 4');
15+
return 4.0 * inside / cycles;
2716
}
17+
18+
console_log(calculatePI(100000));
2819
}

0 commit comments

Comments
 (0)