Comment

Comment by ianm218

Very cool! I have been working on scripting in Rust recently on a Lua project [1].

When you made Roto what kind of workloads were you optimizing for? How are you guys benchmarking performance?

I ran a quick benchmark based on my recent work (Used AI for the code here): ``` fn sum_scalar(n: u64) -> u64 { let total = 0; let i = 0; while i < n { total = total + i; i = i + 1; } total }

  fn sum_list(xs: List[u64]) -> u64 {
      let total = 0;
      for x in xs { total = total + x; }
      total
  }
```

Rust benchmark.rs ```

  use std::time::Instant;
  use roto::{List, Runtime};

  fn main() {
      let rt = Runtime::new();
      let mut pkg = rt.compile("bench.roto").unwrap();
      let sum_list   = pkg.get_function::<fn(List<u64>) -> u64>("sum_list").unwrap();

      let n = 1024;
      let iters = 50_000;
      let xs: List<u64> = (0..n).collect();

      let t = Instant::now();
      for _ in 0..iters { sum_scalar.call(n); }          // adds 0..n with a counter
      let scalar = t.elapsed();

      let t = Instant::now();
      for _ in 0..iters { sum_list.call(xs.clone()); }   // adds the SAME 0..n from a List
      let list = t.elapsed();

      println!("sum_scalar (counter):   {scalar:?}");
      println!("sum_list   (List[u64]): {list:?}");
      println!("-> {:.0}x slower", list.as_secs_f64() / scalar.as_secs_f64());
  }
```

  Output:
  sum_scalar (counter):   28.56ms
  sum_list   (List[u64]): 590.48ms
  -> 21x slower

I'm happy to cut a PR against your repo with some of the benchmarks I run on every commit in my own language projects if that would be helpful! [1]. https://github.com/ianm199/lua-rs/tree/main
parent ianm218 5 months ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton