mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Fix raytrace, add overall score to benchmark
This commit is contained in:
@@ -26,6 +26,8 @@ fn main() {
|
||||
|
||||
files.sort();
|
||||
|
||||
let mut results = Vec::<f64>::new();
|
||||
|
||||
for file_path in files {
|
||||
let file_contents = fs::read_to_string(&file_path).expect("Failed to read file contents");
|
||||
|
||||
@@ -83,6 +85,8 @@ fn main() {
|
||||
|
||||
let mut vm = VirtualMachine::new();
|
||||
|
||||
let mut file_results = Vec::<f64>::new();
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
while Instant::now() - start < Duration::from_secs(1) {
|
||||
@@ -90,16 +94,29 @@ fn main() {
|
||||
let result = vm.run(bytecode.clone(), None, &[]);
|
||||
let after = Instant::now();
|
||||
|
||||
print!(" {}ms", after.duration_since(before).as_millis());
|
||||
let duration_ms = after.duration_since(before).as_millis();
|
||||
print!(" {}ms", duration_ms);
|
||||
|
||||
file_results.push(duration_ms as f64);
|
||||
|
||||
if let Err(result) = result {
|
||||
assert!(false, "{}", result.codify());
|
||||
}
|
||||
}
|
||||
|
||||
if file_results.len() > 2 {
|
||||
results.push(geometric_mean(&file_results[1..file_results.len() - 1]));
|
||||
} else {
|
||||
results.push(geometric_mean(&file_results));
|
||||
}
|
||||
|
||||
println!();
|
||||
}
|
||||
|
||||
let score = geometric_mean(&results);
|
||||
|
||||
println!("\nScore: {}ms", score.round());
|
||||
|
||||
if !failed_paths.is_empty() {
|
||||
assert!(false, "See failures above");
|
||||
}
|
||||
@@ -139,3 +156,7 @@ pub fn resolve_entry_path(entry_path: &String) -> ResolvedPath {
|
||||
|
||||
resolved_entry_path
|
||||
}
|
||||
|
||||
fn geometric_mean(vals: &[f64]) -> f64 {
|
||||
vals.iter().product::<f64>().powf(1.0 / vals.len() as f64)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//! bench()
|
||||
|
||||
// The ray tracer code in this file is written by Adam Burmister. It
|
||||
// is available in its original form from:
|
||||
//
|
||||
@@ -616,7 +618,7 @@ class Engine {
|
||||
for (let i = 0; i < scene.shapes.length; i++) {
|
||||
let shape = scene.shapes[i];
|
||||
|
||||
if (shape != exclude) {
|
||||
if (!shapesEq(shape, exclude)) {
|
||||
let info = shape.intersect(ray);
|
||||
if (
|
||||
info.isHit && info.distance! >= 0 && info.distance! < best.distance!
|
||||
@@ -714,7 +716,10 @@ class Engine {
|
||||
shadowInfo = this.testIntersection(shadowRay, scene, info.shape);
|
||||
if (
|
||||
shadowInfo.isHit &&
|
||||
shadowInfo.shape != info.shape /*&& shadowInfo.shape.type != 'PLANE'*/
|
||||
!shapesEq(
|
||||
shadowInfo.shape,
|
||||
info.shape,
|
||||
) /*&& shadowInfo.shape.type != 'PLANE'*/
|
||||
) {
|
||||
let vA = Color.multiplyScalar(color, 0.5);
|
||||
let dB = 0.5 * Math.pow(shadowInfo.shape!.material.transparency, 0.5);
|
||||
@@ -757,6 +762,15 @@ class Engine {
|
||||
}
|
||||
}
|
||||
|
||||
function shapesEq(left: Shape | null, right: Shape | null) {
|
||||
if (left === null || right === null) {
|
||||
return left === right;
|
||||
}
|
||||
|
||||
// TODO: class instance comparison
|
||||
return left.toString() === right.toString();
|
||||
}
|
||||
|
||||
export default function renderScene() {
|
||||
let scene = new Scene();
|
||||
|
||||
Reference in New Issue
Block a user