Skip to content

Commit fc0a168

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 34d7694 + 080456e commit fc0a168

File tree

12 files changed

+614
-0
lines changed

12 files changed

+614
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Package: rchi-benchmarks
2+
Title: Benchmarks
3+
Version: 0.0.0
4+
Authors@R: person("stdlib", "js", role = c("aut","cre"))
5+
Description: Benchmarks.
6+
Depends: R (>=3.3.3)
7+
Imports:
8+
microbenchmark
9+
chi
10+
LazyData: true
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env Rscript
2+
3+
# Set the precision to 16 digits:
4+
options( digits = 16 );
5+
6+
#' Run benchmarks.
7+
#'
8+
#' @examples
9+
#' main();
10+
main <- function() {
11+
# Define benchmark parameters:
12+
name <- "chi";
13+
iterations <- 1000000L;
14+
repeats <- 3;
15+
16+
#' Print the TAP version.
17+
#'
18+
#' @examples
19+
#' print_version();
20+
print_version <- function() {
21+
cat( "TAP version 13\n" );
22+
}
23+
24+
#' Print the TAP summary.
25+
#'
26+
#' @param total Total number of tests.
27+
#' @param passing Total number of passing tests.
28+
#'
29+
#' @examples
30+
#' print_summary( 3, 3 );
31+
print_summary <- function( total, passing ) {
32+
cat( "#\n" );
33+
cat( paste0( "1..", total, "\n" ) ); # TAP plan
34+
cat( paste0( "# total ", total, "\n" ) );
35+
cat( paste0( "# pass ", passing, "\n" ) );
36+
cat( "#\n" );
37+
cat( "# ok\n" );
38+
}
39+
40+
#' Print benchmark results.
41+
#'
42+
#' @param iterations Number of iterations.
43+
#' @param elapsed Elapsed time in seconds.
44+
#'
45+
#' @examples
46+
#' print_results( 10000L, 0.131009101868 );
47+
print_results <- function( iterations, elapsed ) {
48+
rate <- iterations / elapsed;
49+
cat( " ---\n" );
50+
cat( paste0( " iterations: ", iterations, "\n" ) );
51+
cat( paste0( " elapsed: ", elapsed, "\n" ) );
52+
cat( paste0( " rate: ", rate, "\n" ) );
53+
cat( " ...\n" );
54+
}
55+
56+
#' Run a benchmark.
57+
#'
58+
#' ## Notes
59+
#'
60+
#' * We compute and return a total "elapsed" time, rather than the minimum
61+
#' evaluation time, to match benchmark results in other languages (e.g.,
62+
#' Python).
63+
#'
64+
#'
65+
#' @param iterations Number of Iterations.
66+
#' @return Elapsed time in seconds.
67+
#'
68+
#' @examples
69+
#' elapsed <- benchmark( 10000L );
70+
benchmark <- function( iterations ) {
71+
# Run the benchmarks:
72+
results <- microbenchmark::microbenchmark( chi::rchi( 1, runif(1,min=1.0,max=101.0) ), times = iterations );
73+
74+
# Sum all the raw timing results to get a total "elapsed" time:
75+
elapsed <- sum( results$time );
76+
77+
# Convert the elapsed time from nanoseconds to seconds:
78+
elapsed <- elapsed / 1.0e9;
79+
80+
return( elapsed );
81+
}
82+
83+
print_version();
84+
for ( i in 1:repeats ) {
85+
cat( paste0( "# r::", name, "\n" ) );
86+
elapsed <- benchmark( iterations );
87+
print_results( iterations, elapsed );
88+
cat( paste0( "ok ", i, " benchmark finished", "\n" ) );
89+
}
90+
print_summary( repeats, repeats );
91+
}
92+
93+
main();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Package: rchisq-benchmarks
2+
Title: Benchmarks
3+
Version: 0.0.0
4+
Authors@R: person("stdlib", "js", role = c("aut","cre"))
5+
Description: Benchmarks.
6+
Depends: R (>=3.3.3)
7+
Imports:
8+
microbenchmark
9+
LazyData: true
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env Rscript
2+
3+
# Set the precision to 16 digits:
4+
options( digits = 16 );
5+
6+
#' Run benchmarks.
7+
#'
8+
#' @examples
9+
#' main();
10+
main <- function() {
11+
# Define benchmark parameters:
12+
name <- "chisquare";
13+
iterations <- 1000000L;
14+
repeats <- 3;
15+
16+
#' Print the TAP version.
17+
#'
18+
#' @examples
19+
#' print_version();
20+
print_version <- function() {
21+
cat( "TAP version 13\n" );
22+
}
23+
24+
#' Print the TAP summary.
25+
#'
26+
#' @param total Total number of tests.
27+
#' @param passing Total number of passing tests.
28+
#'
29+
#' @examples
30+
#' print_summary( 3, 3 );
31+
print_summary <- function( total, passing ) {
32+
cat( "#\n" );
33+
cat( paste0( "1..", total, "\n" ) ); # TAP plan
34+
cat( paste0( "# total ", total, "\n" ) );
35+
cat( paste0( "# pass ", passing, "\n" ) );
36+
cat( "#\n" );
37+
cat( "# ok\n" );
38+
}
39+
40+
#' Print benchmark results.
41+
#'
42+
#' @param iterations Number of iterations.
43+
#' @param elapsed Elapsed time in seconds.
44+
#'
45+
#' @examples
46+
#' print_results( 10000L, 0.131009101868 );
47+
print_results <- function( iterations, elapsed ) {
48+
rate <- iterations / elapsed;
49+
cat( " ---\n" );
50+
cat( paste0( " iterations: ", iterations, "\n" ) );
51+
cat( paste0( " elapsed: ", elapsed, "\n" ) );
52+
cat( paste0( " rate: ", rate, "\n" ) );
53+
cat( " ...\n" );
54+
}
55+
56+
#' Run a benchmark.
57+
#'
58+
#' ## Notes
59+
#'
60+
#' * We compute and return a total "elapsed" time, rather than the minimum
61+
#' evaluation time, to match benchmark results in other languages (e.g.,
62+
#' Python).
63+
#'
64+
#'
65+
#' @param iterations Number of Iterations.
66+
#' @return Elapsed time in seconds.
67+
#'
68+
#' @examples
69+
#' elapsed <- benchmark( 10000L );
70+
benchmark <- function( iterations ) {
71+
# Run the benchmarks:
72+
results <- microbenchmark::microbenchmark( rchisq( 1, runif(1,min=1.0,max=101.0) ), times = iterations );
73+
74+
# Sum all the raw timing results to get a total "elapsed" time:
75+
elapsed <- sum( results$time );
76+
77+
# Convert the elapsed time from nanoseconds to seconds:
78+
elapsed <- elapsed / 1.0e9;
79+
80+
return( elapsed );
81+
}
82+
83+
print_version();
84+
for ( i in 1:repeats ) {
85+
cat( paste0( "# r::", name, "\n" ) );
86+
elapsed <- benchmark( iterations );
87+
print_results( iterations, elapsed );
88+
cat( paste0( "ok ", i, " benchmark finished", "\n" ) );
89+
}
90+
print_summary( repeats, repeats );
91+
}
92+
93+
main();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Package: rexp-benchmarks
2+
Title: Benchmarks
3+
Version: 0.0.0
4+
Authors@R: person("stdlib", "js", role = c("aut","cre"))
5+
Description: Benchmarks.
6+
Depends: R (>=3.3.3)
7+
Imports:
8+
microbenchmark
9+
LazyData: true
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env Rscript
2+
3+
# Set the precision to 16 digits:
4+
options( digits = 16 );
5+
6+
#' Run benchmarks.
7+
#'
8+
#' @examples
9+
#' main();
10+
main <- function() {
11+
# Define benchmark parameters:
12+
name <- "exponential";
13+
iterations <- 1000000L;
14+
repeats <- 3;
15+
16+
#' Print the TAP version.
17+
#'
18+
#' @examples
19+
#' print_version();
20+
print_version <- function() {
21+
cat( "TAP version 13\n" );
22+
}
23+
24+
#' Print the TAP summary.
25+
#'
26+
#' @param total Total number of tests.
27+
#' @param passing Total number of passing tests.
28+
#'
29+
#' @examples
30+
#' print_summary( 3, 3 );
31+
print_summary <- function( total, passing ) {
32+
cat( "#\n" );
33+
cat( paste0( "1..", total, "\n" ) ); # TAP plan
34+
cat( paste0( "# total ", total, "\n" ) );
35+
cat( paste0( "# pass ", passing, "\n" ) );
36+
cat( "#\n" );
37+
cat( "# ok\n" );
38+
}
39+
40+
#' Print benchmark results.
41+
#'
42+
#' @param iterations Number of iterations.
43+
#' @param elapsed Elapsed time in seconds.
44+
#'
45+
#' @examples
46+
#' print_results( 10000L, 0.131009101868 );
47+
print_results <- function( iterations, elapsed ) {
48+
rate <- iterations / elapsed;
49+
cat( " ---\n" );
50+
cat( paste0( " iterations: ", iterations, "\n" ) );
51+
cat( paste0( " elapsed: ", elapsed, "\n" ) );
52+
cat( paste0( " rate: ", rate, "\n" ) );
53+
cat( " ...\n" );
54+
}
55+
56+
#' Run a benchmark.
57+
#'
58+
#' ## Notes
59+
#'
60+
#' * We compute and return a total "elapsed" time, rather than the minimum
61+
#' evaluation time, to match benchmark results in other languages (e.g.,
62+
#' Python).
63+
#'
64+
#'
65+
#' @param iterations Number of Iterations.
66+
#' @return Elapsed time in seconds.
67+
#'
68+
#' @examples
69+
#' elapsed <- benchmark( 10000L );
70+
benchmark <- function( iterations ) {
71+
# Run the benchmarks:
72+
results <- microbenchmark::microbenchmark( rexp( 1, runif(1,min=0.0,max=100.0)+.Machine$double.eps ), times = iterations );
73+
74+
# Sum all the raw timing results to get a total "elapsed" time:
75+
elapsed <- sum( results$time );
76+
77+
# Convert the elapsed time from nanoseconds to seconds:
78+
elapsed <- elapsed / 1.0e9;
79+
80+
return( elapsed );
81+
}
82+
83+
print_version();
84+
for ( i in 1:repeats ) {
85+
cat( paste0( "# r::", name, "\n" ) );
86+
elapsed <- benchmark( iterations );
87+
print_results( iterations, elapsed );
88+
cat( paste0( "ok ", i, " benchmark finished", "\n" ) );
89+
}
90+
print_summary( repeats, repeats );
91+
}
92+
93+
main();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Package: rpois-benchmarks
2+
Title: Benchmarks
3+
Version: 0.0.0
4+
Authors@R: person("stdlib", "js", role = c("aut","cre"))
5+
Description: Benchmarks.
6+
Depends: R (>=3.3.3)
7+
Imports:
8+
microbenchmark
9+
LazyData: true

0 commit comments

Comments
 (0)