Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da1675f

Browse filesBrowse files
Add benchmarks for Data to JSValue and vice versa
1 parent 1d99c0f commit da1675f
Copy full SHA for da1675f

2 files changed

+24-1Lines changed: 24 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Benchmarks/Package.swift‎

Copy file name to clipboardExpand all lines: Benchmarks/Package.swift
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ let package = Package(
1010
targets: [
1111
.executableTarget(
1212
name: "Benchmarks",
13-
dependencies: ["JavaScriptKit"],
13+
dependencies: [
14+
"JavaScriptKit",
15+
.product(name: "JavaScriptFoundationCompat", package: "JavaScriptKit"),
16+
],
1417
exclude: ["Generated/JavaScript", "bridge-js.d.ts"],
1518
swiftSettings: [
1619
.enableExperimentalFeature("Extern")
Collapse file

‎Benchmarks/Sources/Benchmarks.swift‎

Copy file name to clipboardExpand all lines: Benchmarks/Sources/Benchmarks.swift
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import JavaScriptKit
2+
import JavaScriptFoundationCompat
3+
import Foundation
24

35
class Benchmark {
46
init(_ title: String) {
@@ -75,4 +77,22 @@ class Benchmark {
7577
}
7678
}
7779
}
80+
81+
do {
82+
let conversion = Benchmark("Conversion")
83+
let data = Data(repeating: 0, count: 10_000)
84+
conversion.testSuite("Data to JSTypedArray") {
85+
for _ in 0..<1_000_000 {
86+
_ = data.jsTypedArray
87+
}
88+
}
89+
90+
let uint8Array = data.jsTypedArray
91+
92+
conversion.testSuite("JSTypedArray to Data") {
93+
for _ in 0..<1_000_000 {
94+
_ = Data.construct(from: uint8Array)
95+
}
96+
}
97+
}
7898
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.