Skip to content
Draft
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
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
* Add `entriesFrom` and `reverseEntriesFrom` to `Map`, `valuesFrom` and `reverseValuesFrom` to `Set` and `Text.toText` (#272).
* Update code examples in doc comments (#224, #282, #303, #315).

## 0.5.0

* Add `concat` of slices function.

## 0.4.0

* Add `isReplicated : () -> Bool` to `InternetComputer` (#213).
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ It's also possible to use both versions in parallel:

```toml
base = "0.14.4"
new-base = "0.4.0"
new-base = "0.5.0"
```

Since this is a preview release for community feedback, expect breaking changes.
Expand Down
72 changes: 72 additions & 0 deletions bench/List/ConcatSlices.bench.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Bench "mo:bench";

import List "../../src/List";
import Nat "../../src/Nat";
import Runtime "../../src/Runtime";
import Iter "../../src/Iter";

module {
public func init() : Bench.Bench {
let bench = Bench.Bench();

bench.name("Create list from two slices");
bench.description("Create two lists of size given in the column, create a new list by concatenating middle halves of each list. Each row is a different concatenation method.");

bench.rows([
"List.concatSlices",
"List.fromIter . Iter.concat . List.range",
"List.addCount_ . List.values_from_",
"List.addCount . List.valuesFrom"
]);
bench.cols([
"1000",
"100000",
"1000000"
]);

bench.runner(
func(row, col) {
let ?size = Nat.fromText(col) else Runtime.trap("Invalid size");
let start = size / 4;
let end = size - start : Nat;
let count = end - start : Nat;
let list1 = List.repeat<Nat>(1, size);
let list2 = List.repeat<Nat>(2, size);
let result : List.List<Nat> = switch row {
case "List.concatSlices" {
List.concatSlices([(list1, start, end), (list2, start, end)])
};
case "List.fromIter . Iter.concat . List.range" {
List.fromIter(Iter.concat(List.range(list1, start, end), List.range(list2, start, end)))
};
case "List.addCount_ . List.values_from_" {
let list = List.empty<Nat>();
List.addCount_(list, List.values_from_(start, list1), count);
List.addCount_(list, List.values_from_(start, list2), count);
list
};
case "List.addCount . List.valuesFrom" {
let list = List.empty<Nat>();
List.addCount(list, List.valuesFrom(list1, start), count);
List.addCount(list, List.valuesFrom(list2, start), count);
list
};
case _ Runtime.unreachable()
};
assert List.size(result) == count * 2;
// Uncomment to check that the result is correct
// var i = 0;
// while (i < List.size(result)) {
// if (i < count) {
// assert List.get(result, i) == 1
// } else {
// assert List.get(result, i) == 2
// };
// i += 1
// }
}
);

bench
}
}
72 changes: 72 additions & 0 deletions bench/List/Iteration.bench.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Bench "mo:bench";

import List "../../src/List";
import Nat "../../src/Nat";
import Runtime "../../src/Runtime";

module {
public func init() : Bench.Bench {
let bench = Bench.Bench();

bench.name("List iteration");
bench.description("");

bench.rows([
"while get",
"List.values_ while unsafe_next",
"while put",
"List.values_ while next_set"
]);
bench.cols([
"1000",
"100000",
"1000000"
]);

func onValue(value : Nat) {
ignore value
};

bench.runner(
func(row, col) {
let ?size = Nat.fromText(col) else Runtime.trap("Invalid size");
let list = List.repeat<Nat>(0, size);
switch row {
case "while get" {
var i = 0;
while (i < size) {
onValue(List.get(list, i));
i += 1
}
};
case "List.values_ while unsafe_next" {
let unsafeIter = List.values_(list);
var i = 0;
while (i < size) {
onValue(unsafeIter.unsafe_next());
i += 1
}
};
case "while put" {
var i = 0;
while (i < size) {
List.put(list, i, i * 2);
i += 1
}
};
case "List.values_ while next_set" {
let unsafeIter = List.values_(list);
var i = 0;
while (i < size) {
unsafeIter.next_set(i * 2);
i += 1
}
};
case _ Runtime.unreachable()
}
}
);

bench
}
}
2 changes: 1 addition & 1 deletion mops.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "new-base"
version = "0.4.0"
version = "0.5.0"
description = "The new Motoko base library (preview)"
repository = "https://github.com/dfinity/new-motoko-base"
keywords = [
Expand Down
Loading
Loading