Skip to content

Commit 342af47

Browse files
waterlensbobzhang
authored andcommitted
feat: benchmark utility
1 parent 0309f04 commit 342af47

17 files changed

+372
-93
lines changed

array/fixedarray.mbt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,6 @@ test "mapi" {
297297
assert_eq!(doubled, [2, 5, 8, 11, 14])
298298
}
299299
300-
///|
301-
test "makei" {
302-
let empty = FixedArray::makei(0, fn(_i) { { val: 3 } })
303-
assert_eq!(empty.length(), 0)
304-
let simple_arr = FixedArray::makei(1, fn(_i) { { val: 2 } })
305-
assert_eq!(simple_arr.length(), 1)
306-
assert_eq!(simple_arr[0].val, 2)
307-
let arr = FixedArray::makei(2, fn(_i) { { val: 1 } })
308-
assert_eq!(arr.length(), 2)
309-
@test.is_not!(arr[0], arr[1])
310-
assert_eq!(arr[0].val, 1)
311-
assert_eq!(arr[1].val, 1)
312-
}
313-
314300
///|
315301
/// Creates a new fixed-size array of the specified length, where each element is
316302
/// initialized using a function that maps indices to values.

array/fixedarray_test.mbt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,17 @@ test "FixedArray::arbitrary" {
9090
content="[[0, 0, 0, 1, 0, -1, 0, -1], [0, 0, 0, 1], [0, 0, 0, -1, -1, -1, 4], [0, 0], [0, 0, -1, 2]]",
9191
)
9292
}
93+
94+
///|
95+
test "FixedArray::makei" {
96+
let empty = FixedArray::makei(0, fn(_i) { { val: 3 } })
97+
assert_eq!(empty.length(), 0)
98+
let simple_arr = FixedArray::makei(1, fn(_i) { { val: 2 } })
99+
assert_eq!(simple_arr.length(), 1)
100+
assert_eq!(simple_arr[0].val, 2)
101+
let arr = FixedArray::makei(2, fn(_i) { { val: 1 } })
102+
assert_eq!(arr.length(), 2)
103+
@test.is_not!(arr[0], arr[1])
104+
assert_eq!(arr[0].val, 1)
105+
assert_eq!(arr[1].val, 1)
106+
}

array/moon.pkg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"moonbitlang/core/builtin",
44
"moonbitlang/core/bytes",
55
"moonbitlang/core/string",
6-
"moonbitlang/core/test",
76
"moonbitlang/core/quickcheck",
87
"moonbitlang/core/quickcheck/splitmix"
98
],
109
"test-import": [
10+
"moonbitlang/core/test",
1111
"moonbitlang/core/prelude",
1212
"moonbitlang/core/random",
1313
"moonbitlang/core/json"

bench/bench.mbt

Lines changed: 0 additions & 15 deletions
This file was deleted.

bench/bench_test.mbt

Lines changed: 0 additions & 27 deletions
This file was deleted.

bench/moon.pkg.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

bench/types.mbt

Lines changed: 0 additions & 16 deletions
This file was deleted.

builtin/builtin.mbti

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ impl ArrayView {
144144
}
145145
impl[X : ToJson] ToJson for ArrayView[X]
146146

147+
pub(all) type! BenchError String
148+
147149
type BigInt
148150
impl BigInt {
149151
#deprecated

builtin/console.mbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ pub fn inspect(
231231
/// ```
232232
pub(all) type! SnapshotError String
233233
234+
///|
235+
pub(all) type! BenchError String
236+
234237
///|
235238
test "panic error case of inspect" {
236239
let x : Int = 42

bench/monotonic_clock_js.mbt renamed to test/monotonic_clock_js.mbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
///|
1516
extern type Timestamp
17+
1618
///|
1719
pub extern "js" fn monotonic_clock_start() -> Timestamp =
1820
#| () => performance.now()

bench/monotonic_clock_native.mbt renamed to test/monotonic_clock_native.mbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
///|
1516
extern type Timestamp
1617

bench/monotonic_clock_wasm.mbt renamed to test/monotonic_clock_wasm.mbt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
///|
1514

16-
extern type Instant
15+
///|
16+
extern type Timestamp
1717

18-
fn instant_elapsed_as_secs_f64(x : Instant) -> Double = "__moonbit_time_unstable" "instant_elapsed_as_secs_f64"
18+
///|
19+
fn instant_elapsed_as_secs_f64(x : Timestamp) -> Double = "__moonbit_time_unstable" "instant_elapsed_as_secs_f64"
1920

2021
///|
21-
pub fn monotonic_clock_start() -> Instant = "__moonbit_time_unstable" "instant_now"
22+
pub fn monotonic_clock_start() -> Timestamp = "__moonbit_time_unstable" "instant_now"
2223

2324
///|
24-
pub fn monotonic_clock_end(ts : Instant) -> Double {
25-
let elapsed_secs: Double = instant_elapsed_as_secs_f64(ts);
25+
pub fn monotonic_clock_end(ts : Timestamp) -> Double {
26+
let elapsed_secs : Double = instant_elapsed_as_secs_f64(ts)
2627
elapsed_secs * 1000000.0
2728
}

test/moon.pkg.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
2-
"import": ["moonbitlang/core/builtin"],
2+
"targets": {
3+
"monotonic_clock_js.mbt": ["js"],
4+
"monotonic_clock_wasm.mbt": ["wasm", "wasm-gc"],
5+
"monotonic_clock_native.mbt": ["native"]
6+
},
7+
"import": [
8+
"moonbitlang/core/builtin",
9+
"moonbitlang/core/double",
10+
"moonbitlang/core/array",
11+
"moonbitlang/core/json"
12+
],
313
"test-import": ["moonbitlang/core/prelude"]
414
}

0 commit comments

Comments
 (0)