Skip to content

Commit

Permalink
Adds benchmark tests and README with results
Browse files Browse the repository at this point in the history
  • Loading branch information
tachyon-ops committed Apr 1, 2021
1 parent 53d5aa6 commit 8b94242
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static int Main(string[] args)
}


Console.WriteLine("Exiting...");
Console.WriteLine("Exiting...\n");
return 0;
}

Expand Down
87 changes: 71 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# csts

Typescript runtime in C# (WIP and PoC trial)
Note that this is a Proof Of Concept! By all means this is not to be used for production, and is intended as a SandBox and test ground. It is intended to defy the very assumptions most people hold when they think 'javascript' or 'typescript' need to be executed in a browser. No, that is not a necessity and one could even implement assembly code from either to compile to native architectures.
Be aware that you are entering an opinionated real, for which barriers need to be taken down. The first barrier is always our dearest: what we assume we know - and usually it is our biggest fault and impediment to progress. It is a collective fault of mankind, as without it I am sure we wouldn't be in such an ecologic hassle, having move past our problems.

This is the attempt to prove that we use too much processing power because we are lazy: we build with simple tools and languages - no harm there, and we should all aim to do that - but we care not to improve the foundations of our technology stack. Today, we surely burn through energy and batteries with our CPUs at a rate that could be improved, if only we had less browser driven development even for native applications.

If we as developers do that, shouldn't we also aim to clean up and build a more pristine foundation? I believe we should. If you believe so as well, reach out and try your best. You might learn a lot with that mindset.

## Why?

Expand All @@ -13,7 +19,7 @@ And... why not?

- `dotnet publish -r osx-x64` (just publishes)

- See more at [https://avaloniaui.net/docs/packing/macOS#manual](https://avaloniaui.net/docs/packing/macOS#manual)
- See more at [https://avaloniaui.net/docs/packing/macOS#manual](https://avaloniaui.net/docs/packing/macOS#manual)

- `dotnet msbuild -t:BundleApp -p:RuntimeIdentifier=osx-x64` (bundles into TypeScriptNative.app)

Expand All @@ -24,6 +30,7 @@ And... why not?
## How to run?

If you have only build the debug, use the following:

- ./bin/Debug/net5.0/osx-x64/TypeScriptNative

## How?
Expand All @@ -39,28 +46,27 @@ Note: ANTLR was dropped in favour of a manual approach as it is not that much wo

## Unsupported / not implemented

* const
* let
* import
* types
* you can type vars and functions but it will do nothing as of now
* as Type
- const
- let
- import
- types
- you can type vars and functions but it will do nothing as of now
- as Type

## Edge cases

* `println("a" + 3);` right now we error it, but according to JS implementation, we should
allow for it to be concatenated: `a3`. We will warn the user, but allow it.

- `println("a" + 3);` according to JS implementation, we should allow for it to be concatenated: `a3` . Warns the user, but allows it.

## LL code to EXEC

1. `llc code.ll` -> generates `code.s`
2. `gcc code.s -o code` -> generates `code` executable: run it by `./code`

From: [SO how can I create an executable from LLVM IR](https://stackoverflow.com/questions/45985953/how-can-i-create-an-executable-from-llvm-ir)

## Resources

- Test TypeScript: https://codesandbox.io/s/react-typescript-playground-forked-ipe11?file=/src/index.tsx
- [Test TypeScript](https://codesandbox.io/s/react-typescript-playground-forked-ipe11?file=/src/index.tsx)

- [Roman language (and how to interpret a simple ANTLR)](https://gjdanis.github.io/2016/01/23/roman/) and a [SO](https://codereview.stackexchange.com/questions/117711/roman-numerals-with-antlr) to explain further.

Expand All @@ -75,13 +81,62 @@ allow for it to be concatenated: `a3`. We will warn the user, but allow it.
- [ANTLR jar](https://www.antlr.org/download.html)
- [The Definitive ANTLR 4 Reference](https://pragprog.com/titles/tpantlr2/the-definitive-antlr-4-reference/)

- https://stackoverflow.com/questions/63542345/how-to-detect-for-loop-block-after-parsing-the-code-using-antlr

* https://stackoverflow.com/questions/63542345/how-to-detect-for-loop-block-after-parsing-the-code-using-antlr

* http://franckgaspoz.fr/en/first-steps-with-antlr4-in-csharp/
- http://franckgaspoz.fr/en/first-steps-with-antlr4-in-csharp/

* https://stackoverflow.com/questions/29971097/how-to-create-ast-with-antlr4
- https://stackoverflow.com/questions/29971097/how-to-create-ast-with-antlr4

# Big thanks to LOX!

Check out the amazing online book [Crafting Interpreters](https://craftinginterpreters.com) by Bob Nystrom.
Check out the amazing online book [Crafting Interpreters](https://craftinginterpreters.com) by Bob Nystrom.

# Benchmark

Here are a abit of juicy results for you :)

## CPP Benchmark

Go to `benchmarks/cpp` and execute

`time ./benchmarks/c/hello ./examples/time-benchmark.ts`

Expected output:

```
Hello, world!
./benchmarks/c/hello ./examples/time-benchmark.ts 0.00s user 0.00s system 69% cpu 0.005 total
```

## Deno Benchmark

Install [deno](https://deno.land) and:

`time deno run ./examples/time-benchmark.ts`

Output:

```
Check file:///Users/nmpribeiro/work/prog_lang/csts_gh/examples/time-benchmark.ts
Hello world
deno run ./examples/time-benchmark.ts 0.49s user 0.03s system 140% cpu 0.371 total
```

## TypeScriptNative Benchmark

`time ./bin/Debug/net5.0/osx-x64/TypeScriptNative ./examples/time-benchmark.ts`

Output:

```
============================================
|| ::Welcome:: ||
|| TypeScript Native PoC v0.1 ||
============================================
Running from the following path: ./examples
Get: Undefined variable 'console'.
[line 10]
Exiting...
./bin/Debug/net5.0/osx-x64/TypeScriptNative ./examples/time-benchmark.ts 0.07s user 0.02s system 108% cpu 0.083 total
```
Binary file added benchmarks/c/hello
Binary file not shown.
8 changes: 8 additions & 0 deletions benchmarks/c/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <iostream>

int
main ()
{
std::cout << "Hello, world!\n";
return 0;
}
Binary file added examples/Archive.zip
Binary file not shown.
10 changes: 10 additions & 0 deletions examples/time-benchmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// import { Console } from "./import/Console";

// export class Console {
// log(message) {
// println(message);
// }
// }
// var console = new Console();
// console.log("test");
console.log("Hello world");

0 comments on commit 8b94242

Please sign in to comment.