-
-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
3,118 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Jint.Benchmark | ||
{ | ||
[MemoryDiagnoser] | ||
public class TypedArrayBenchmark | ||
{ | ||
private const string script = @" | ||
var testArray = new Int32Array([29, 27, 28, 838, 22, 2882, 2, 93, 84, 74, 7, 933, 3754, 3874, 22838, 38464, 3837, 82424, 2927, 2625, 63, 27, 28, 838, 22, 2882, 2, 93, 84, 74, 7, 933, 3754, 3874, 22838, 38464, 3837, 82424, 2927, 2625, 63, 27, 28, 838, 22, 2882, 2, 93, 84, 74, 7, 933, 3754, 3874, 22838, 38464, 3837, 82424, 2927, 2625, 63, 27, 28, 838, 22, 2882, 2, 93, 84, 74, 7, 933, 3754, 3874, 22838, 38464, 3837, 82424, 2927, 2625, 63]); | ||
"; | ||
|
||
private Engine engine; | ||
|
||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
engine = new Engine(); | ||
engine.Execute(script); | ||
} | ||
|
||
[Params(100)] | ||
public int N { get; set; } | ||
|
||
[Benchmark] | ||
public void Slice() | ||
{ | ||
for (var i = 0; i < N; ++i) | ||
{ | ||
engine.Execute("testArray.slice();"); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Concat() | ||
{ | ||
// tests conversion performance as TypedArray does not have concat | ||
for (var i = 0; i < N; ++i) | ||
{ | ||
engine.Execute("[].concat(testArray);"); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Index() | ||
{ | ||
for (var i = 0; i < N; ++i) | ||
{ | ||
engine.Execute(@" | ||
var obj2 = new Int32Array(testArray.length); | ||
for (var i = 0, l = testArray.length; i < l; i++) { | ||
obj2[i] = testArray[i]; | ||
} | ||
"); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Map() | ||
{ | ||
for (var i = 0; i < N; ++i) | ||
{ | ||
engine.Execute(@" | ||
var obj2 = testArray.map(function(i) { | ||
return i; | ||
}); | ||
"); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void Apply() | ||
{ | ||
for (var i = 0; i < N; ++i) | ||
{ | ||
engine.Execute("Array.apply(undefined, testArray);"); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void JsonStringifyParse() | ||
{ | ||
for (var i = 0; i < N; ++i) | ||
{ | ||
engine.Execute("JSON.parse(JSON.stringify(testArray));"); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void FilterWithNumber() | ||
{ | ||
for (var i = 0; i < N; ++i) | ||
{ | ||
engine.Execute("testArray.filter(function(i) { return i > 55; });"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Xunit; | ||
|
||
namespace Jint.Tests.Test262.BuiltIns | ||
{ | ||
public class TypedArrayTests : Test262Test | ||
{ | ||
[Theory(DisplayName = "built-ins\\TypedArray")] | ||
[MemberData(nameof(SourceFiles), "built-ins\\TypedArray", false)] | ||
[MemberData(nameof(SourceFiles), "built-ins\\TypedArray", true, Skip = "Skipped")] | ||
protected void TypedArray(SourceFile sourceFile) | ||
{ | ||
RunTestInternal(sourceFile); | ||
} | ||
|
||
[Theory(DisplayName = "built-ins\\TypedArrayConstructors")] | ||
[MemberData(nameof(SourceFiles), "built-ins\\TypedArrayConstructors", false)] | ||
[MemberData(nameof(SourceFiles), "built-ins\\TypedArrayConstructors", true, Skip = "Skipped")] | ||
protected void TypedArrayConstructors(SourceFile sourceFile) | ||
{ | ||
RunTestInternal(sourceFile); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using Xunit; | ||
|
||
namespace Jint.Tests.Runtime | ||
{ | ||
public class TypedArrayInteropTests | ||
{ | ||
[Fact] | ||
public void CanInteropWithInt8() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("testSubject", engine.Realm.Intrinsics.Int8Array.Construct(new sbyte[] { 42 })); | ||
ValidateCreatedTypeArray(engine, "Int8Array"); | ||
} | ||
|
||
[Fact] | ||
public void CanInteropWithUint8() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("testSubject", engine.Realm.Intrinsics.Uint8Array.Construct(new byte[] { 42 })); | ||
ValidateCreatedTypeArray(engine, "Uint8Array"); | ||
} | ||
|
||
[Fact] | ||
public void CanInteropWithUint8Clamped() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("testSubject", engine.Realm.Intrinsics.Uint8ClampedArray.Construct(new byte[] { 42 })); | ||
ValidateCreatedTypeArray(engine, "Uint8ClampedArray"); | ||
} | ||
|
||
[Fact] | ||
public void CanInteropWithInt16() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("testSubject", engine.Realm.Intrinsics.Int16Array.Construct(new short[] { 42 })); | ||
ValidateCreatedTypeArray(engine, "Int16Array"); | ||
} | ||
|
||
[Fact] | ||
public void CanInteropWithUint16() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("testSubject", engine.Realm.Intrinsics.Uint16Array.Construct(new ushort[] { 42 })); | ||
ValidateCreatedTypeArray(engine, "Uint16Array"); | ||
} | ||
|
||
[Fact] | ||
public void CanInteropWithInt32() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("testSubject", engine.Realm.Intrinsics.Int32Array.Construct(new int[] { 42 })); | ||
ValidateCreatedTypeArray(engine, "Int32Array"); | ||
} | ||
|
||
[Fact] | ||
public void CanInteropWithUint32() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("testSubject", engine.Realm.Intrinsics.Uint32Array.Construct(new uint[] { 42 })); | ||
ValidateCreatedTypeArray(engine, "Uint32Array"); | ||
} | ||
|
||
[Fact(Skip = "BigInt not implemented")] | ||
public void CanInteropWithBigInt64() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("testSubject", engine.Realm.Intrinsics.BigInt64Array.Construct(new long[] { 42 })); | ||
ValidateCreatedTypeArray(engine, "BigInt64Array"); | ||
} | ||
|
||
[Fact(Skip = "BigInt not implemented")] | ||
public void CanInteropWithBigUint64() | ||
{ | ||
var engine = new Engine(); | ||
engine.SetValue("testSubject", engine.Realm.Intrinsics.BigUint64Array.Construct(new ulong[] { 42 })); | ||
ValidateCreatedTypeArray(engine, "BigUint64Array"); | ||
} | ||
|
||
private static void ValidateCreatedTypeArray(Engine engine, string arrayName) | ||
{ | ||
Assert.Equal(arrayName, engine.Evaluate("testSubject.constructor.name").AsString()); | ||
Assert.Equal(1, engine.Evaluate("testSubject.length").AsNumber()); | ||
Assert.Equal(42, engine.Evaluate("testSubject[0]").AsNumber()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.