Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object assign setproto create
(version: 0)
Comparing performance of:
assign vs setproto vs proto vs create vs factory
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
(function(){ function _base() { return { a:111,b:1,c:'2134124141', d:'werrqwer',e:'34234',fffffffff:'324234', gggggg:'99999',jadf:'adsfa',asdfasdf:'asdf',asdfasdf:'sadf', [Math.random()]:Math.random(), [Math.random()]:Math.random() } } (function(){ const base = _base() window.assign = function(x){ return Object.assign({[Math.random()+'x']:Math.random()+'x'+x},base) } })(); (function(){ const base = _base() window.setproto = function(x){ const z = Object.setPrototypeOf({ [Math.random()+'x']: Math.random()+'x'+x },base) return z } })(); (function(){ const base = _base() window.proto = function(x){ const z = { [Math.random()+'x']: Math.random()+'x'+x } z.__proto__ = base return z } })(); (function(){ const base = _base() window.create = function(x){ const p = Object.create(base) p[Math.random()+'x'] = Math.random()+'x'+x return p } })(); (function(){ const base = _base() window.factory = function(x){ const o = _base() o[Math.random()+'x'] = Math.random()+'x'+x return o } })(); })()
Tests:
assign
var red = assign('xx');
setproto
var yellow = setproto('yy');
proto
var z = proto('z');
create
var a = create('a');
factory
var b = factory('b')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
assign
setproto
proto
create
factory
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):
I'll break down the provided benchmark definition and explain what's being tested, compared options, pros and cons, and other considerations. **Benchmark Definition** The benchmark is composed of four test cases: `assign`, `setproto`, `proto`, and `create`. The `factory` test case is not included in the latest benchmark result. Each test case has a unique JavaScript code snippet that defines a function on the global object (`window`). These functions are used to modify objects, specifically setting properties or creating new objects. **Tested Options** The options being compared are: 1. **`assign()`**: This function assigns an object to another object using `Object.assign()`. The assigned object has a property with a dynamic key generated by `Math.random()+'x'`. 2. **`setproto()`**: This function sets the prototype of an object using `Object.setPrototypeOf()`. The specified object is used as the prototype for a new object, and a property is added to the new object with a dynamic key. 3. **`proto()`**: This function creates an object by setting its prototype using `__proto__`. The object created has a property with a dynamic key. 4. **`create()`**: This function creates a new object using `Object.create()`, which takes another object (in this case, the global object) as the prototype. **Pros and Cons** Here's a brief overview of the pros and cons of each option: 1. **`assign()`**: * Pros: Simple to implement, works across browsers. * Cons: May not be supported in older browsers or environments that don't have `Object.assign()`. 2. **`setproto()`**: * Pros: Can be used to create objects with a specific prototype hierarchy. * Cons: Can be slower due to the overhead of `Object.setPrototypeOf()`. 3. **`proto()`**: * Pros: Simple to implement, works across browsers. * Cons: May not work correctly in older browsers or environments that don't support `__proto__`. 4. **`create()`**: * Pros: Works with any object as a prototype. * Cons: Can be slower due to the overhead of `Object.create()`, and may not work correctly in older browsers. **Other Considerations** * The use of dynamic property keys (`Math.random()+'x'`) ensures that each test case creates unique objects, making it easier to compare results. * The benchmark uses Chrome 69 as the browser, but it's likely that the code will need to be tested with other browsers and environments. **Alternatives** Other alternatives for creating or modifying objects include: * `Object.defineProperty()`: used to define properties on an object, which can be slower than `assign()` or `setproto()`. * `Object.assign()` in older browsers (e.g., IE 11): may not work correctly due to differences in behavior. In summary, the benchmark tests four different methods for creating or modifying objects: `assign()`, `setproto()`, `proto()`, and `create()`. Each method has its pros and cons, and understanding these trade-offs can help developers choose the best approach for their specific use cases.
Related benchmarks:
obj assign setproto
obj assign setproto create
obj inheritance create assign setproto
Switch vs Object Literal larger
Comments
Confirm delete:
Do you really want to delete benchmark?