Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
vwd streamer
(version: 0)
Comparing performance of:
originBenchmark vs optimizedBenchmark
Created:
8 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var fields = []; for (var i = 0; i < 1000; i++) { fields[i] = 'vwdId-' + i + '.vwdField'; } // create duplications fields = fields.concat(fields, fields);
Tests:
originBenchmark
var _streamerInstance = { _subscribe: function () {}, _unsubscribe: function () {}, _getCachedValue: function () {}, _update: function () {} }; var _subscribedFields = {}; var subscribe = function (fields) { if (!fields) { return } else if (typeof fields === "string") { fields = [fields] } var duplicateSubscriptions = []; for (var fieldIndex = 0; fieldIndex < fields.length; fieldIndex++) { var fieldName = fields[fieldIndex]; if (_subscribedFields[fieldName]) { duplicateSubscriptions.push(fieldIndex) } else { _subscribedFields[fieldName] = true } var cachedValue = _streamerInstance._getCachedValue(fieldName); if (cachedValue != null) { _streamerInstance._update(cachedValue.dataName, cachedValue.value, cachedValue.dataType, this) } } if (duplicateSubscriptions.length > 0) { fields = fields.slice(0); for (var i = duplicateSubscriptions.length - 1; i >= 0; i--) { fields.splice(duplicateSubscriptions[i], 1) } } _streamerInstance._subscribe(fields); } var unsubscribe = function (fields) { if (!fields) { return } else if (typeof fields === "string") { fields = [fields] } var invalidFields = []; for (var fieldIndex = 0; fieldIndex < fields.length; fieldIndex++) { var fieldName = fields[fieldIndex]; if (_subscribedFields[fieldName]) { delete _subscribedFields[fieldName] } else { invalidFields.push(fieldIndex) } } if (invalidFields.length > 0) { fields = fields.slice(0); for (var i = invalidFields.length - 1; i >= 0; i--) { fields.splice(invalidFields[i], 1) } } _streamerInstance._unsubscribe(fields); }; subscribe(fields); unsubscribe(fields);
optimizedBenchmark
var _streamerInstance = { _subscribe: function () {}, _unsubscribe: function () {}, _getCachedValue: function () {}, _update: function () {} }; var _subscribedFields = {}; var subscribe = function (fields) { if (!fields) { return } else if (typeof fields === "string") { fields = [fields] } var fieldsToSubscribe = []; var fieldsToSubscribeCount = 0; var length = fields.length; for (var fieldIndex = 0; fieldIndex < length; fieldIndex++) { var fieldName = fields[fieldIndex]; if (!_subscribedFields[fieldName]) { fieldsToSubscribe[fieldsToSubscribeCount] = fieldIndex; fieldsToSubscribeCount++; _subscribedFields[fieldName] = true } var cachedValue = _streamerInstance._getCachedValue(fieldName); if (cachedValue != null) { _streamerInstance._update(cachedValue.dataName, cachedValue.value, cachedValue.dataType, this) } } _streamerInstance._subscribe(fieldsToSubscribe); } var unsubscribe = function (fields) { if (!fields) { return } else if (typeof fields === "string") { fields = [fields] } var fieldsToUnsubscribe = []; var fieldsToUnsubscribeCount = 0; var length = fields.length; for (var fieldIndex = 0; fieldIndex < length; fieldIndex++) { var fieldName = fields[fieldIndex]; if (_subscribedFields[fieldName]) { fieldsToUnsubscribe[fieldsToUnsubscribeCount] = fieldName; fieldsToUnsubscribeCount++; delete _subscribedFields[fieldName] } } _streamerInstance._unsubscribe(fieldsToUnsubscribe); }; subscribe(fields); unsubscribe(fields);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
originBenchmark
optimizedBenchmark
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 test cases and explain what's being tested. **Benchmark Definition** The Benchmark Definition is a JSON object that describes the script to be executed during the benchmarking process. In this case, we have two benchmark definitions: 1. `originBenchmark`: This definition creates an instance of `_streamerInstance` with four methods: `_subscribe`, `_unsubscribe`, `_getCachedValue`, and `_update`. It then defines a `subscribe` function that takes an array of fields as input and performs some operations on them. The function also calls the `_update` method for each field. 2. `optimizedBenchmark`: This definition is similar to `originBenchmark`, but it uses a different approach to process the fields. Instead of using an array of indices, it creates two arrays: `fieldsToSubscribe` and `fieldsToUnsubscribe`. It then iterates over these arrays, calling the `_update` method for each field. **What's being tested** The main difference between these two benchmark definitions is how they handle duplicate subscriptions and unsubscriptions. The `originBenchmark` definition uses a simple approach where it checks if a field has already been subscribed to and removes any duplicates from the subscription array. The `optimizedBenchmark` definition, on the other hand, uses a more complex approach that creates two separate arrays for subscribed and unsubscribed fields. **Pros and Cons** Here are some pros and cons of each approach: 1. `originBenchmark`: * Pros: Simple and easy to understand. * Cons: May be slower due to the duplicate removal step. 2. `optimizedBenchmark`: * Pros: Faster performance, especially for large datasets. * Cons: More complex code and harder to understand. **Library** There is no explicit library mentioned in the Benchmark Definition. However, based on the code, it appears that `_streamerInstance` is a custom class with methods `_subscribe`, `_unsubscribe`, `_getCachedValue`, and `_update`. These methods are likely responsible for handling the subscription and unsubscription logic. **Device and Browser** The benchmark results are reported for two different browsers: Chrome 60 on a Macintosh platform (both `originBenchmark` and `optimizedBenchmark`). The device platform is listed as "Other". **RawUAString** This field contains the raw User Agent string, which can be used to identify the browser and device. Overall, these benchmark definitions are testing the performance of two different approaches to handling duplicate subscriptions and unsubscriptions in a subscription-based system.
Related benchmarks:
ad1235
reduce 20000 v2
JS arrays..
spread2021
spread20211
Comments
Confirm delete:
Do you really want to delete benchmark?