Skip to content

Instantly share code, notes, and snippets.

@ebuckley
Last active September 29, 2016 11:44
Show Gist options
  • Save ebuckley/6221116e35133d7f114894101a2169c3 to your computer and use it in GitHub Desktop.
Save ebuckley/6221116e35133d7f114894101a2169c3 to your computer and use it in GitHub Desktop.

Ramda Usage across three MS projects

I used a three part method to get data for this investigation

Step one collect project statistics

Use this ack command in the project root directory to scan for Ramda functions. I wrote out the results to a data file.

ack -oh \
  --ignore-dir="styleguide" \
  --ignore-dir="client/bower_components" \
  --ignore-dir="client/dist" \
  --ignore-dir="client/tmp" \
  --ignore-dir="./node_modules" \
  --ignore-dir="client/node_modules" \
  --type="js" "R\.\w+" . > datafile

Step two get a list of all ramda functions

Scrape a list of Ramda functions from their http://ramdajs.com/0.22.1/docs/ . Open up the JS console on the site, then run this javascript to extract a json dump of the data.

arr = [];
document.querySelectorAll('.toc li.func').forEach(el => arr.push(el.getAttribute('data-name')));
JSON.stringify(arr, '\t')

Step two use a script to get summary statistics

I was interested in the top 10 functions used in each project. My usage data was not perfect, so I needed to reject some of the captured results by checking that the captured function name was actually part of the ramda library. Once I had the filtered set of data, I could simply count the unique function names, sort them, and then take the top 10 from that list.

const R = require('ramda')
const fs = require('fs')
const dataFiles = ['leapfrog-ramda-results', 'sarr-ramda-results', 'water-allocation-ramda-results']
const ramdaFunctions = require('./ramda-functions')

// get a breakdown of the ramda function to the number of times it is used
// data -> { ["ramdafunction"]: count}
const getBreakDown = R.pipe(
  R.split('\n'),
  R.map(fn => R.split('.', fn)[1]),
  R.filter(R.contains(R.__, ramdaFunctions)),
  R.groupBy(R.identity),
  R.map(obj => obj.length)
)

// take the breakdown and return the top 10 items
// { ["ramdafunction"]: count} -> { ["ramdafunction"]: count}
const topTen = R.pipe(
  R.toPairs,
  R.sortBy(R.prop(1)),
  R.reverse,
  R.take(10),
  R.fromPairs
)

dataFiles.forEach(file => {
  var data
  try {
    data = fs.readFileSync(file).toString()
  } catch (e) {
    console.error(e)
    process.exit(1)
  }
  console.log('stats for ', file)
  console.log('Top 10 functions used:')
  console.log(R.pipe(getBreakDown, topTen)(data))
})

The Raw Data

stats for  leapfrog-ramda-results
Top 10 functions used:
{ map: 15,
  filter: 15,
  path: 15,
  pipe: 10,
  merge: 9,
  prop: 8,
  head: 8,
  pick: 7,
  take: 5,
  clone: 5 }
stats for  sarr-ramda-results
Top 10 functions used:
{ pipe: 87,
  map: 75,
  prop: 40,
  compose: 35,
  merge: 30,
  contains: 28,
  curryN: 27,
  filter: 27,
  curry: 26,
  values: 25 }
stats for  water-allocation-ramda-results
Top 10 functions used:
{ pipe: 127,
  map: 110,
  pluck: 96,
  prop: 80,
  isNil: 56,
  filter: 38,
  propEq: 32,
  flatten: 30,
  merge: 30,
  reject: 28 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment