Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion json/from_json.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub impl[V : FromJson] FromJson for Map[String, V] with fn from_json(json, path)
guard json is Object(obj) else {
decode_error(path, "Map::from_json: expected object")
}
let res = Map([])
let res = Map([], capacity=obj.capacity())
// As above: the test cannot fail, it just makes `key` assignable.
guard! JsonPath::Key(path, key="") is (Key(_) as new_path)
// Map::map_with_key
Expand Down
40 changes: 40 additions & 0 deletions json/from_json_map_bench_test.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2026 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

///|
fn from_json_map_bench_input(size : Int) -> Json {
let object : Map[String, Json] = Map([], capacity=size)
for i in 0..<size {
object[i.to_string()] = Json::number(i.to_double())
}
Json::object(object)
}

///|
test "bench Map::from_json entries=10000" (it : @bench.T) {
let input = from_json_map_bench_input(10000)
it.bench(fn() {
let decoded : Map[String, Int] = try! @json.from_json(input)
it.keep(decoded.length())
})
}

///|
test "bench Map::from_json entries=100000" (it : @bench.T) {
let input = from_json_map_bench_input(100000)
it.bench(fn() {
let decoded : Map[String, Int] = try! @json.from_json(input)
it.keep(decoded.length())
})
}
Loading