From 3c94605074f7af8b5a1034a0a2eb38c883a301cb Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Thu, 26 Jan 2023 20:46:29 +0100 Subject: [PATCH] [wasm] Add Vector.Normalize measurement --- src/mono/sample/wasm/browser-bench/Vector.cs | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/mono/sample/wasm/browser-bench/Vector.cs b/src/mono/sample/wasm/browser-bench/Vector.cs index 20741b3ffa2f3a..343332783555fd 100644 --- a/src/mono/sample/wasm/browser-bench/Vector.cs +++ b/src/mono/sample/wasm/browser-bench/Vector.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Runtime.Intrinsics; namespace Sample @@ -28,6 +29,7 @@ public VectorTask() new MaxFloat(), new MinDouble(), new MaxDouble(), + new Normalize(), }; } @@ -301,5 +303,25 @@ public override void RunStep() { result = Vector128.Max(vector1, vector2); } } + + class Normalize : VectorMeasurement + { + Vector128 result; + float x, y, z, w; + public override string Name => "Normalize float"; + + public Normalize() + { + x = Random.Shared.NextSingle(); + y = Random.Shared.NextSingle(); + z = Random.Shared.NextSingle(); + w = Random.Shared.NextSingle(); + } + + public override void RunStep() { + Vector128 vector = Vector128.Create(x, y, z, w); + result = vector / (float)Math.Sqrt(Vector128.Dot(vector, vector)); + } + } } }