Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Ramda's `where` vs. my `whereAll` - Part 1 - Single Property Tests
(version: 53)
Comparing performance of:
Using `R.where` vs Using `whereAll`
Created:
9 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://unpkg.com/ramda@0.23.0/dist/ramda.js"></script>
Script Preparation code:
// Sort of like a recursive version of Ramda's `where` (http://ramdajs.com/docs/#where). var whereAll = R.curry((spec, obj) => { if (typeof obj === "undefined") { if (spec === null || typeof spec === "boolean") { return !spec } return false } else if (spec === false) { return false } var output = true R.forEachObjIndexed((v, k) => { if (v === null || typeof v === "boolean" || R.keys(v).length) { if (!whereAll(v, obj[k])) { output = false } } else if (!v(obj[k])) { output = false } }, spec) return output }) // ----------------------------------------------------------------------------- var data = [ '{ Z: 1 }', "{ q: undefined }", "{ q: null }", "{ q: false }", "{ q: true }", "{ q: Infinity }", "{ q: 1 }", "{ q: 0 }", "{ q: NaN }", '{ q: "" }', ] var specs = [ "{ q: null }", "{ q: true }", "{ q: false }", "{ q: R.identity }", "{ q: R.equals(true) }", "{ q: R.equals(false) }", "{ q: R.equals(null) }", "{ q: R.equals(undefined) }", "{ q: R.identical(true) }", "{ q: R.identical(false) }", "{ q: R.identical(null) }", "{ q: R.identical(undefined) }", "{ q: R.always(true) }", "{ q: R.always(false) }", "{ q: R.always(null) }", "{ q: R.always(undefined) }", "{ q: Infinity }", "{ q: 1 }", "{ q: 0 }", "{ q: NaN }", '{ q: "" }', "{ q: [] }", "{ q: {} }", "{ q: undefined }", ] // In the truth table that gets generated, `false` is omitted and errors // are shown as `⊥` for sake of readability. function generateTruthTable(f) { var table = {} for (var i in specs) { var row = {} var spec = eval("(" + specs[i] + ")") for (var j in data) { var r try { r = f(spec, eval("(" + data[j] + ")")) } catch (_) { r = "⊥" } if (r) row[data[j]] = r } table[specs[i]] = row } return table }
Tests:
Using `R.where`
generateTruthTable(R.where)
Using `whereAll`
generateTruthTable(whereAll)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Using `R.where`
Using `whereAll`
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares two functions: Ramda's `where` and a custom implementation called `whereAll`. The goal is to determine which function is faster for a set of test cases. **Options Compared** Two options are being compared: 1. **Ramda's `where`**: A functional programming library that provides various higher-order functions, including `where`. 2. **Custom `whereAll` implementation**: A custom implementation of the `where` function created by the benchmark author. **Pros and Cons of Each Approach** Here are some pros and cons of each approach: **Ramda's `where`** Pros: * Well-tested and maintained by a large community * Provides a robust and efficient implementation * Can be easily reused in other projects Cons: * May not be optimized for specific use cases (e.g., the custom implementation is specifically designed for this benchmark) * Requires an external library (Ramda) **Custom `whereAll` implementation** Pros: * Specifically designed for this benchmark, which may result in better performance * No external dependencies required Cons: * Less well-tested and maintained than Ramda's implementation * May not be as robust or efficient as Ramda's implementation **Library: Ramda** Ramda is a functional programming library that provides various higher-order functions. In this benchmark, `where` is used to filter objects based on a condition. The library provides a robust and efficient implementation of the `where` function. **Special JS Feature/Syntax** There are some special JavaScript features and syntax used in the custom implementation: * `R.curry`: A technique for creating curried functions, which allows the `whereAll` function to be called with different arguments. * `eval()`: Used to dynamically evaluate expressions within the test cases. **Benchmark Preparation Code** The benchmark preparation code is a JavaScript file that defines the `whereAll` implementation and the test data. It also includes a utility function `generateTruthTable()` that generates a truth table for each test case. **Other Alternatives** If you're interested in exploring other alternatives, here are some options: * **Lodash**: Another popular functional programming library that provides similar functions to Ramda. * **Built-in JavaScript functions**: You could use built-in JavaScript functions like `Array.prototype.filter()` or `Object.keys().forEach()` instead of the custom implementation. Keep in mind that these alternatives may not provide the same level of performance or functionality as the custom implementation, which is specifically designed for this benchmark.
Related benchmarks:
Ramda's `where` vs. my `whereAll` - Part 2 - Example Code From the Documentation for `R.where`
Ramda's `where` vs. my `whereAll` - Part 3 - Nested Spec
Ramda vs. VanillaJS - Find an object by prop
Ramda isNil vs vanilla JS
Comments
Confirm delete:
Do you really want to delete benchmark?