-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvement to the Natural Order Sort (#3276)
* Improved Natural Order Data generator for benchmarking * Missing Import Benchmark script * Update Natural_Order.enso Restore missing ToDo * Changelog * PR Comments * PR Comments * Additional comments. * Correction
- Loading branch information
1 parent
9f051ad
commit 68b85de
Showing
5 changed files
with
154 additions
and
58 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
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,39 @@ | ||
from Standard.Base import all | ||
|
||
polyglot java import java.util.Random | ||
polyglot java import org.enso.base.Text_Utils | ||
|
||
upper_case_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".utf_8 | ||
numbers = "0123456789".utf_8 | ||
|
||
## Creates a random number generator which can be used for creating test values. | ||
|
||
Arguments: | ||
- seed: Optional seed value to make the sequence deterministic | ||
make_generator : Integer -> Random | ||
make_generator (seed = 0) = | ||
if seed == 0 then Random.new else Random.new seed | ||
|
||
|
||
## Creates a random string based on a template and random number generator. | ||
|
||
Arguments: | ||
- template: Vector of character arrays that represent the possible | ||
characters for each letter. | ||
- generator: Random number generator | ||
|
||
> Examples: | ||
Creates a fake UK National Insurance number: | ||
|
||
l = "ABCEGHJKLMNOPRSTWXYZ".utf_8 | ||
n = "0123456789".utf_8 | ||
s = "ABCDFMP ".utf_8 | ||
template = [l, l, n, n, n, n, n, s] | ||
ni_number = make_string template make_generator | ||
make_string : Vector -> Any -> Text | ||
make_string template generator = | ||
output = Array.new template.length | ||
0.up_to template.length . each i-> | ||
a = template.at i | ||
output.set_at i (a.at (generator.nextInt a.length)) | ||
Text_Utils.from_utf_8 output |
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,28 @@ | ||
from Standard.Base import all | ||
|
||
import Standard.Test.Bench | ||
|
||
import Standard.Test.Faker | ||
import Standard.Base.Data.Ordering.Natural_Order | ||
|
||
## Bench Utilities ============================================================ | ||
|
||
vector_size = 10000 | ||
iter_size = 100 | ||
num_iterations = 10 | ||
|
||
|
||
# The Benchmarks ============================================================== | ||
|
||
main = | ||
l = Faker.upper_case_letters | ||
n = Faker.numbers | ||
template = [l, l, l, n, n, n, n, n, l] | ||
|
||
## No specific significance to this constant, just fixed to make generated set deterministic | ||
fixed_random_seed = 1644575867 | ||
random_generator = Faker.make_generator fixed_random_seed | ||
|
||
unsorted = 0.up_to here.vector_size . map _->(Faker.make_string template random_generator) | ||
|
||
Bench.measure (unsorted.sort by=Natural_Order.compare) "Natural Order" here.iter_size here.num_iterations |