2021-10-12 10:30:02 -04:00
|
|
|
// Benchmarking of sorting of ASG into xmle sections
|
|
|
|
//
|
2022-05-03 14:14:29 -04:00
|
|
|
// Copyright (C) 2014-2022 Ryan Specialty Group, LLC.
|
2021-10-12 10:30:02 -04:00
|
|
|
//
|
|
|
|
// This file is part of TAME.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate tamer;
|
|
|
|
extern crate test;
|
|
|
|
|
2022-05-19 10:09:49 -04:00
|
|
|
use tamer::num::Dtype;
|
2021-10-12 10:30:02 -04:00
|
|
|
use test::Bencher;
|
|
|
|
|
2022-05-19 10:09:49 -04:00
|
|
|
use tamer::asg::{DefaultAsg, IdentKind, Source};
|
2021-10-14 12:37:32 -04:00
|
|
|
use tamer::ld::xmle::{lower::sort, Sections};
|
2021-10-12 10:30:02 -04:00
|
|
|
use tamer::sym::{GlobalSymbolIntern, SymbolId};
|
|
|
|
|
2022-05-12 15:44:32 -04:00
|
|
|
type TestAsg = DefaultAsg;
|
2021-10-12 10:30:02 -04:00
|
|
|
|
|
|
|
fn interned_n(n: u16) -> Vec<SymbolId> {
|
|
|
|
(0..n).map(|i| i.to_string().intern()).collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn sort_1_with_1_000_existing_supernode(bench: &mut Bencher) {
|
|
|
|
let mut sut = TestAsg::new();
|
|
|
|
let xs = interned_n(1_000);
|
|
|
|
|
|
|
|
let orefs = xs
|
|
|
|
.iter()
|
|
|
|
.map(|sym| {
|
|
|
|
sut.declare(
|
|
|
|
*sym,
|
2022-05-19 10:09:49 -04:00
|
|
|
IdentKind::Rate(Dtype::Integer),
|
2021-10-12 10:30:02 -04:00
|
|
|
Source::default(),
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
let root = orefs[0];
|
|
|
|
|
|
|
|
// All edges from a single node.
|
|
|
|
orefs.iter().skip(1).for_each(|to| {
|
|
|
|
sut.add_dep(root, *to);
|
|
|
|
});
|
|
|
|
|
tamer: asg: Track roots on graph
Previously, since the graph contained only identifiers, discovered roots
were stored in a separate vector and exposed to the caller. This not only
leaked details, but added complexity; this was left over from the
refactoring of the proof-of-concept linker some time ago.
This moves the root management into the ASG itself, mostly, with one item
being left over for now in the asg_builder (eligibility classifications).
There are two roots that were added automatically:
- __yield
- __worksheet
The former has been removed and is now expected to be explicitly mapped in
the return map, which is now enforced with an extern in `core/base`. This
is still special, in the sense that it is explicitly referenced by the
generated code, but there's nothing inherently special about it and I'll
continue to generalize it into oblivion in the future, such that the final
yield is just a convention.
`__worksheet` is the only symbol of type `IdentKind::Worksheet`, and so that
was generalized just as the meta and map entries were.
The goal in the future will be to have this more under the control of the
source language, and to consolodate individual roots under packages, so that
the _actual_ roots are few.
As far as the actual ASG goes: this introduces a single root node that is
used as the sole reference for reachability analysis and topological
sorting. The edges of that root node replace the vector that was removed.
DEV-11864
2022-05-17 10:42:05 -04:00
|
|
|
sut.add_root(root);
|
|
|
|
|
2021-10-12 10:30:02 -04:00
|
|
|
bench.iter(|| {
|
tamer: asg: Track roots on graph
Previously, since the graph contained only identifiers, discovered roots
were stored in a separate vector and exposed to the caller. This not only
leaked details, but added complexity; this was left over from the
refactoring of the proof-of-concept linker some time ago.
This moves the root management into the ASG itself, mostly, with one item
being left over for now in the asg_builder (eligibility classifications).
There are two roots that were added automatically:
- __yield
- __worksheet
The former has been removed and is now expected to be explicitly mapped in
the return map, which is now enforced with an extern in `core/base`. This
is still special, in the sense that it is explicitly referenced by the
generated code, but there's nothing inherently special about it and I'll
continue to generalize it into oblivion in the future, such that the final
yield is just a convention.
`__worksheet` is the only symbol of type `IdentKind::Worksheet`, and so that
was generalized just as the meta and map entries were.
The goal in the future will be to have this more under the control of the
source language, and to consolodate individual roots under packages, so that
the _actual_ roots are few.
As far as the actual ASG goes: this introduces a single root node that is
used as the sole reference for reachability analysis and topological
sorting. The edges of that root node replace the vector that was removed.
DEV-11864
2022-05-17 10:42:05 -04:00
|
|
|
drop(sort(&sut, Sections::new()));
|
2021-10-12 10:30:02 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn sort_1_with_1_000_existing_one_edge_per_node_one_path(bench: &mut Bencher) {
|
|
|
|
let mut sut = TestAsg::new();
|
|
|
|
let xs = interned_n(1_000);
|
|
|
|
|
|
|
|
let orefs = xs
|
|
|
|
.iter()
|
|
|
|
.map(|sym| {
|
|
|
|
sut.declare(
|
|
|
|
*sym,
|
2022-05-19 10:09:49 -04:00
|
|
|
IdentKind::Rate(Dtype::Integer),
|
2021-10-12 10:30:02 -04:00
|
|
|
Source::default(),
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
// Note that there's no `cycle` call on the iterator, like the
|
|
|
|
// above tests, to make sure we don't create a cycle on the
|
|
|
|
// graph.
|
|
|
|
orefs
|
|
|
|
.iter()
|
|
|
|
.zip(orefs.iter().skip(1))
|
|
|
|
.for_each(|(from, to)| {
|
|
|
|
sut.add_dep(*from, *to);
|
|
|
|
});
|
|
|
|
|
|
|
|
let root = orefs[0];
|
|
|
|
|
tamer: asg: Track roots on graph
Previously, since the graph contained only identifiers, discovered roots
were stored in a separate vector and exposed to the caller. This not only
leaked details, but added complexity; this was left over from the
refactoring of the proof-of-concept linker some time ago.
This moves the root management into the ASG itself, mostly, with one item
being left over for now in the asg_builder (eligibility classifications).
There are two roots that were added automatically:
- __yield
- __worksheet
The former has been removed and is now expected to be explicitly mapped in
the return map, which is now enforced with an extern in `core/base`. This
is still special, in the sense that it is explicitly referenced by the
generated code, but there's nothing inherently special about it and I'll
continue to generalize it into oblivion in the future, such that the final
yield is just a convention.
`__worksheet` is the only symbol of type `IdentKind::Worksheet`, and so that
was generalized just as the meta and map entries were.
The goal in the future will be to have this more under the control of the
source language, and to consolodate individual roots under packages, so that
the _actual_ roots are few.
As far as the actual ASG goes: this introduces a single root node that is
used as the sole reference for reachability analysis and topological
sorting. The edges of that root node replace the vector that was removed.
DEV-11864
2022-05-17 10:42:05 -04:00
|
|
|
sut.add_root(root);
|
|
|
|
|
2021-10-12 10:30:02 -04:00
|
|
|
bench.iter(|| {
|
tamer: asg: Track roots on graph
Previously, since the graph contained only identifiers, discovered roots
were stored in a separate vector and exposed to the caller. This not only
leaked details, but added complexity; this was left over from the
refactoring of the proof-of-concept linker some time ago.
This moves the root management into the ASG itself, mostly, with one item
being left over for now in the asg_builder (eligibility classifications).
There are two roots that were added automatically:
- __yield
- __worksheet
The former has been removed and is now expected to be explicitly mapped in
the return map, which is now enforced with an extern in `core/base`. This
is still special, in the sense that it is explicitly referenced by the
generated code, but there's nothing inherently special about it and I'll
continue to generalize it into oblivion in the future, such that the final
yield is just a convention.
`__worksheet` is the only symbol of type `IdentKind::Worksheet`, and so that
was generalized just as the meta and map entries were.
The goal in the future will be to have this more under the control of the
source language, and to consolodate individual roots under packages, so that
the _actual_ roots are few.
As far as the actual ASG goes: this introduces a single root node that is
used as the sole reference for reachability analysis and topological
sorting. The edges of that root node replace the vector that was removed.
DEV-11864
2022-05-17 10:42:05 -04:00
|
|
|
drop(sort(&sut, Sections::new()));
|
2021-10-12 10:30:02 -04:00
|
|
|
});
|
|
|
|
}
|