-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
59 lines (48 loc) · 1.63 KB
/
Program.cs
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
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.InteropServices.JavaScript;
using MathNet.Numerics.LinearAlgebra;
public partial class MyClass
{
[JSExport]
internal static void DoMath(int n)
{
SetText("Running...");
var matrixA = Matrix<double>.Build.Random(n,n);
var vectorB = Vector<double>.Build.Random(n);
TimedResult result = TimeIt(() => matrixA.Solve(vectorB)); // Solve Ax = b
SetText($"{result.Result}\nTime taken: {result.Time} ms");
}
struct TimedResult
{
public double Time;
public Vector<double> Result;
}
static TimedResult TimeIt(Func<Vector<double>> f)
{
var start = DateTimeOffset.Now;
var result = f();
var end = DateTimeOffset.Now;
var time = (end - start).TotalMilliseconds;
return new TimedResult { Time = time, Result = result };
}
[JSImport("MyClass.updateTick", "main.js")]
static partial void UpdateTick(string message);
[JSImport("MyClass.setText", "main.js")]
static partial void SetText(string message);
[JSExport]
public static async Task Tick()
{
string[] pix = {"🅰", "🅱", "🅲", "🅳", "🅴", "🅵", "🅶", "🅷", "🅸", "🅹", "🅺", "🅻", "🅼", "🅽", "🅾", "🅿︎", "🆀", "🆁", "🆂", "🆃", "🆄", "🆅", "🆆", "🆇", "🆈", "🆉"};
int i = 0;;
while (true) {
UpdateTick(pix[i]);
if (++i >= pix.Length) {
i = 0;
}
await Task.Delay (500);
}
}
public static void Main() {}
}