Skip to content

Commit 4c69ad8

Browse files
Additional additions to performance
1 parent ee0cf0f commit 4c69ad8

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ inst/doc
1717

1818
docs
1919
tools/coding-helpers.R
20+
target/rust-analyzer/flycheck0/stderr
21+
target/rust-analyzer/flycheck0/stdout

vignettes/performance.Rmd

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ generate_graphs <- function(n, p) {
6363

6464
#### Relational queries
6565

66-
```{r bench-press}
66+
We start with parents/children:
67+
68+
```{r benchmark-parents-children}
6769
graphs <- generate_graphs(1000, p = 0.25) # dense graph
6870
cg <- graphs$cg
6971
ig <- graphs$ig
@@ -94,32 +96,42 @@ bench::mark(
9496
dagitty::parents(dg, test_node_name)
9597
dagitty::children(dg, test_node_name)
9698
},
97-
check = FALSE # rust output are indexes, so check fails
99+
check = FALSE # igraph returns igraph object
98100
)
99101
```
100102

101-
`bnlearn` is fastest here, but is only able to handle smaller graphs, whereas `caugi` can handle very large graph objects with almost no time increase:
103+
`bnlearn` is fastest here, but is only able to handle smaller graphs, whereas `caugi` and `igraph` can handle very large graph objects with almost no time increase:
102104

103105
```{r benchmark-parents-children-large-graph}
104106
large_cg <- generate_graph(n = 40000, m = 1000000, class = "DAG")
107+
large_ig <- as_igraph(large_cg)
105108
test_node_index <- sample.int(40000, 1)
106109
test_node_name <- paste0("V", test_node_index)
107110
bench::mark(
108-
caugi_named = {
111+
caugi = {
109112
caugi::parents(large_cg, test_node_name)
110113
caugi::children(large_cg, test_node_name)
111-
}
114+
},
115+
igraph = {
116+
igraph::neighbors(large_ig, test_node_name, mode = "in")
117+
igraph::neighbors(large_ig, test_node_name, mode = "out")
118+
},
119+
check = FALSE
112120
)
113121
```
114122

115-
For ancestors and descendants, we see that `caugi` outperforms all other packages by a large margin:
123+
For ancestors and descendants, we see that `caugi` outperforms all other packages by a several magnitudes, expect for `igraph`, which it still beats, but by a smaller margin::
116124

117-
```{r an-de-an}
125+
```{r benchmark-an-de}
118126
bench::mark(
119127
caugi = {
120128
caugi::ancestors(cg, "V500")
121129
caugi::descendants(cg, "V500")
122130
},
131+
igraph = {
132+
igraph::subcomponent(ig, "V500", mode = "in")
133+
igraph::subcomponent(ig, "V500", mode = "out")
134+
},
123135
bnlearn = {
124136
bnlearn::ancestors(bng, "V500")
125137
bnlearn::descendants(bng, "V500")
@@ -129,7 +141,7 @@ bench::mark(
129141
dagitty::descendants(dg, "V500")
130142
},
131143
iterations = 10,
132-
check = FALSE # dagitty returns V500 as well.
144+
check = FALSE # dagitty returns V500 as well and igraph returns an igraph
133145
)
134146
```
135147

@@ -156,7 +168,6 @@ bench::mark(
156168
Here we see an example of where the frontloading hurts performance. When we build a subgraph, we have to rebuild the entire `caugi` graph object. Here, we see that while `caugi` outperforms other packages for queries (except for parents/children for `bnlearn`), it is slower for building the graph objects themselves, which shows for the subgraph benchmark:
157169

158170
```{r benchmark-subgraph}
159-
160171
subgraph_nodes_index <- sample.int(1000, 500)
161172
subgraph_nodes <- paste0("V", subgraph_nodes_index)
162173
bench::mark(

0 commit comments

Comments
 (0)