| 1 | {{{ |
| 2 | library(ggplot2) |
| 3 | library(microbenchmark) |
| 4 | library(network) |
| 5 | library(ergm) |
| 6 | data('faux.magnolia.high') |
| 7 | fmh <- faux.magnolia.high |
| 8 | }}} |
| 9 | |
| 10 | Since researching ticket #866, I accidentally started benchmarking as.matrix.network.adjacency which has nothing to do with the ticket. Regardless, I wanted to capture some of the attempts at doing so. Code can be found in my devolper branch [12933/statnet_commons]. |
| 11 | |
| 12 | In the following tests, I compare the run-time of functions orig() and proposed(). orig() always represents the original code and proposed() always represents the attempted optimized code. |
| 13 | |
| 14 | Results of setting an edge attribute of type character: |
| 15 | |
| 16 | |
| 17 | {{{ |
| 18 | set.edge.attribute(fmh,'dummy','foo') |
| 19 | orig <- function() as.matrix.network.adjacency.orig(fmh,'dummy') |
| 20 | proposed <- function() as.matrix.network.adjacency(fmh,'dummy') |
| 21 | res <- microbenchmark(orig(),proposed(),times=100) |
| 22 | summary(res) |
| 23 | }}} |
| 24 | |
| 25 | {{{ |
| 26 | ## expr min lq median uq max neval |
| 27 | ## 1 orig() 1446.9 1469.7 1480.5 1582.0 1751 100 |
| 28 | ## 2 proposed() 525.7 544.6 549.5 556.3 1546 100 |
| 29 | }}} |
| 30 | |
| 31 | {{{ |
| 32 | qplot(y=time,colour=expr,data=res) |
| 33 | }}} |
| 34 | |
| 35 | [[Image(unnamed-chunk-3.png)]] |
| 36 | |
| 37 | Results of setting an edge attribute of type numeric: |
| 38 | |
| 39 | |
| 40 | {{{ |
| 41 | set.edge.attribute(fmh,'dummy',2) |
| 42 | orig <- function() as.matrix.network.adjacency.orig(fmh,'dummy') |
| 43 | proposed <- function() as.matrix.network.adjacency(fmh,'dummy') |
| 44 | res <- microbenchmark(orig(),proposed(),times=100) |
| 45 | summary(res) |
| 46 | }}} |
| 47 | |
| 48 | {{{ |
| 49 | ## expr min lq median uq max neval |
| 50 | ## 1 orig() 309.4 420.9 424.7 428.2 653.8 100 |
| 51 | ## 2 proposed() 280.5 387.0 390.3 394.7 613.8 100 |
| 52 | }}} |
| 53 | |
| 54 | {{{ |
| 55 | qplot(y=time,colour=expr,data=res) |
| 56 | }}} |
| 57 | |
| 58 | [[Image(unnamed-chunk-5.png)]] |
| 59 | |
| 60 | Results of setting an edge attribute of type integer: |
| 61 | |
| 62 | |
| 63 | {{{ |
| 64 | set.edge.attribute(fmh,'dummy',3L) |
| 65 | orig <- function() as.matrix.network.adjacency.orig(fmh,'dummy') |
| 66 | proposed <- function() as.matrix.network.adjacency(fmh,'dummy') |
| 67 | res <- microbenchmark(orig(),proposed(),times=100) |
| 68 | summary(res) |
| 69 | }}} |
| 70 | |
| 71 | {{{ |
| 72 | ## expr min lq median uq max neval |
| 73 | ## 1 orig() 306.5 420.6 423.8 430.6 771.9 100 |
| 74 | ## 2 proposed() 269.7 381.9 384.4 389.1 493.0 100 |
| 75 | }}} |
| 76 | |
| 77 | {{{ |
| 78 | qplot(y=time,colour=expr,data=res) |
| 79 | }}} |
| 80 | |
| 81 | [[Image(unnamed-chunk-7.png)]] |