Skip to content

Instantly share code, notes, and snippets.

@kevinushey
Last active January 3, 2016 01:29
Show Gist options
  • Save kevinushey/a8a7c8991749a42461d3 to your computer and use it in GitHub Desktop.
Save kevinushey/a8a7c8991749a42461d3 to your computer and use it in GitHub Desktop.
Counting numbers of lines per feature in Rcpp, Rcpp11
Total number of lines of code in 'inst/include' of Rcpp is (excluding headers) 86759.
Total number of lines of code in 'inst/include' of Rcpp11 is (excluding headers) 25531.
$module
$module$Rcpp
[1] 51491
$module$Rcpp11
[1] 1849
$create
$create$Rcpp
[1] 1209
$create$Rcpp11
[1] 73
$generated
$generated$Rcpp
[1] 59485
$generated$Rcpp11
[1] 0
## total word counts in inst/include dirs for Rcpp, Rcpp11
## we strip out the initial headers
dirs <- c("~/Rcpp", "~/Rcpp11")
names(dirs) <- c("Rcpp", "Rcpp11")
strip_header <- function(txt, comment="//") {
regex <- paste0("^", comment)
## assume the first line must be a header
if (!grepl(regex, txt[1])) {
return(txt)
}
comments <- grep(regex, txt)
diff <- diff(comments)
if (all(diff == 1)) { ## all comments are part of the header
return(txt[ (length(comments)+1):length(txt) ])
} else {
header_end <- which( diff != 1 )[1]
return( txt[ (header_end+1):length(txt) ] )
}
}
for (i in seq_along(dirs)) {
dir <- dirs[[i]]
files <- list.files( file.path(dir, "inst/include"), recursive=TRUE, full.names=TRUE, pattern=".h$")
sizes <- lapply(files, function(file) {
txt <- readLines(file)
txt <- strip_header(txt)
return (length(txt))
})
total <- sum( unlist(sizes) )
cat("Total number of lines of code in 'inst/include' of ", names(dirs)[i],
" is (excluding headers) ", total, ".\n", sep="")
}
## line count per feature
features <- c("module", "create", "generated")
feature <- features[[1]]
dir <- dirs[[1]]
output <- lapply(features, function(feature) {
sapply(dirs, function(dir) {
files <- list.files( file.path(dir, "inst/include"), recursive=TRUE, full.names=TRUE )
files <- grep(feature, files, value=TRUE)
sapply(files, function(file) {
length( strip_header( readLines(file) ) )
})
})
})
names(output) <- features
for (i in seq_along(output)) {
names( output[[i]] ) <- names(dirs)
}
## total sizes by feature
print(lapply(output, function(x) lapply(x, function(xx) sum( unlist(xx) ))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment