kmill / lean4-raytracer Goto Github PK
View Code? Open in Web Editor NEWA simple raytracer written in Lean 4
License: Apache License 2.0
A simple raytracer written in Lean 4
License: Apache License 2.0
There is no license file and the readme does not mention a license.
The repo should have a license file.
The following numbers were produced on my personal laptop with various programs running in the background (<5% noise). ASUS ZenBook UX434FAC (i7-10510U).
I've only run the default test once per version. I recommend using https://docs.rs/hyperfine for accurate benchmark results on a dedicated server with intentionally minimal noise and a static clock.
All single-threaded implementations clock around 3.7 GHz (+/- 0.1GHz), while the multi-threaded C clocked around 2.1 GHz (+/- 0.1 GHz) per core.
(Normalized to single threaded C time. Lower is better.)
Master branch Lean. 3.53x (~34m 30s)
Optimize branch Lean. 2.89x (~28m 16s) (I guess this implementation differs too much to be a fair comparison?)
Single threaded C. 1x (~9m 46s)
Multi-threaded C. 0.42x (~4m 9s) (Obviously flawed comparison)
--- render.c 2021-10-20 +0000
+++ render-single-core.c 2021-10-20 +0000
@@ -592,7 +592,7 @@
printf("Starting %d threads.\n", num_threads);
- pthread_t threads[num_threads];
+ struct RenderData *threads[num_threads];
for (int i = 0; i < num_threads; i++) {
struct RenderData *rd = malloc(sizeof(struct RenderData));
@@ -606,7 +606,8 @@
rd->nobj = nobj;
Rand_split(&rand, &rd->rand);
rd->show_progress = (i == 0);
- pthread_create(&threads[i], NULL, &render_task, (void*)rd);
+ render_task(rd);
+ threads[i] = rd;
}
Color *pixels = malloc(height * width * sizeof(Color));
@@ -615,8 +616,7 @@
}
for (int i = 0; i < num_threads; i++) {
- struct RenderData *rd = NULL;
- pthread_join(threads[i], (void **)&rd);
+ struct RenderData *rd = threads[i];
Color *new_pixels = rd->pixels;
for (int i = 0; i < height * width; i++) {
pixels[i] = Vec3_add(pixels[i], new_pixels[i]);
I'm not sure if the C benchmark here is meant to be "optimised to the hilt" or just reasonably representative. Obviously you want it to somewhat correspond to the Lean implementation, but it's possible to teach the compiler more about this code.
All the functions except main
in render.c could be marked static. Alternatively, -fwhole-program
has the same effect in GCC. This improves the compiler's ability (or maybe willingness) to inline and specialize functions. Link-time optimisation could also be added on top of this with -flto
that might further accelerate it.
Maybe these comments are not relevant and you just wanted to compare against reasonably optimised C. But if not, I hope these comments are helpful.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.