<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js"></script>
var blocks = [
{
"id": "bv2Q3fR8j",
"width": 160,
"height": 160,
"name": "blank",
"type": "blank",
"op": {
"type": "blank"
},
"view": {
"type": "BlankBlock"
},
"handlers": {
"source": true,
"target": true
},
"x": 0,
"y": 0,
"validate": {
"rule": "equal",
"value": "input.array.ability"
}
},
{
"id": "6e5aE55OD",
"width": 160,
"height": 160,
"type": "label",
"op": {
"type": "label"
},
"view": {
"type": "LabelBlock"
},
"name": "answer",
"required": true,
"handlers": {
"source": true,
"target": null
},
"x": 0,
"y": 300
},
{
"id": "ULidMw-z2",
"width": 160,
"height": 160,
"name": "onehot",
"type": "preprocessing.OneHot",
"op": {
"type": "preprocessing.OneHot"
},
"view": {
"type": "EmptyBlock"
},
"handlers": {
"source": true,
"target": true
},
"options": {
"max_len": 24,
"feature_columns": [
{
"key": "type1",
"vocabulary_list": [
"normal",
"grass",
"dragon",
"bug",
"ice",
"water",
"fighting",
"poison",
"ground",
"psychic",
"rock",
"fire",
"electric",
"ghost",
"dark",
"steel",
"fairy",
"flying"
]
}
]
},
"hidden": true,
"required": true
},
{
"id": "kSWU25MDc",
"width": 160,
"height": 160,
"name": "Preprocessing",
"type": "preprocessing.ConstantScaler",
"op": {
"type": "preprocessing.ConstantScaler"
},
"view": {
"type": "EmptyBlock"
},
"handlers": {
"source": true,
"target": true
},
"options": {
"value": 0.00392156862
},
"hidden": true,
"required": true
},
{
"id": "T2-7CdlVh",
"width": 160,
"height": 160,
"name": "blank",
"type": "blank",
"op": {
"type": "blank"
},
"view": {
"type": "BlankBlock"
},
"handlers": {
"source": true,
"target": true
},
"x": 250,
"y": 0,
"validate": {
"rule": "equal",
"value": "layer.PokemonTiny"
}
},
{
"id": "yNHnSTUb6",
"width": 160,
"height": 160,
"name": "prediction",
"type": "generatedLabels",
"op": {
"type": "generatedLabels"
},
"view": {
"type": "GeneratedLabelsBlock"
},
"required": true,
"handlers": {
"source": null,
"target": true
},
"x": 500,
"y": 0,
"options": {
"labels": [
"일반",
"전설"
],
"onlyTop": true
}
}
]
R.find(R.pipe(R.prop('type'), R.includes('Preprocessing')))(blocks)
R.find((block) => block.type === "Preprocessing")(blocks)
blocks.find((block) => block.type === "Preprocessing")
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Ramda find with R.pipe | |
Ramda find | |
Native find |
Test name | Executions per second |
---|---|
Ramda find with R.pipe | 194221.1 Ops/sec |
Ramda find | 1055377.5 Ops/sec |
Native find | 4756480.0 Ops/sec |
I'll provide an in-depth explanation of the benchmark, its options, and other considerations.
Benchmark Overview
The benchmark is designed to measure the performance of finding a specific object (in this case, blocks with type "Preprocessing") in an array using different methods: Ramda's R.find()
function with and without piping, and native JavaScript's find()
method.
Options Compared
There are three options compared:
pipe
function to compose two functions together. The first function filters the array based on a condition (in this case, R.prop('type')
and R.includes('Preprocessing')
), and the second function checks if the resulting value matches the desired type.find()
function directly to filter the array based on a condition (in this case, block.type === "Preprocessing"
).Performance Considerations
The performance of these options depends on various factors, such as:
R.find()
functionIn general, native JavaScript's find()
method is likely to be faster than Ramda's R.find()
functions because it is implemented in C++ and has direct access to the underlying array. Piping functions together using R.pipe()
can introduce additional overhead due to function call overhead and potential type coercion.
Benchmark Results
The latest benchmark results show that:
find()
method performs best, with an execution rate of 4756480 executions per second.R.find()
with piping is faster than the native method (although not significantly), with an execution rate of 194221.0625 executions per second.R.find()
without piping is slower than both native and piped methods, with an execution rate of 1055377.5 executions per second.Conclusion
In conclusion, this benchmark highlights the importance of considering performance when choosing a filtering method for large datasets. While Ramda's R.find()
functions may provide more concise and readable code, they come at a slight cost in terms of performance compared to native JavaScript's find()
method.