<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://ayrtonms.github.io/mypromise/mypromise.js"></script>
myajax("POST", "http://vanilla-js.com/path/to/api", "banana=yellow")
.done((res) => {
console.log('Success!');
})
.fail((res) => {
console.log('Failure!');
})
.always((res) => {
console.log('Always!');
});
$.ajax({
type: 'POST',
url: "http://vanilla-js.com/path/to/api",
data: "banana=yellow"
})
.done((res) => {
console.log('Success!');
})
.fail((res) => {
console.log('Failure!');
})
.always((res) => {
console.log('Always!');
});;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
my promise | |
Jquery promise |
Test name | Executions per second |
---|---|
my promise | 0.0 Ops/sec |
Jquery promise | 11157.4 Ops/sec |
Let's break down the provided JSON and explain what's being tested.
Benchmark Definition
The benchmark is comparing two approaches: using vanilla JavaScript promises (custom promise
) versus jQuery Deferred Objects (Jquery deferred object
). The goal is to measure their performance in terms of execution speed.
Options compared
Pros and Cons
.then()
methods)..fail()
and logging success with .done()
).Library usage
In the benchmark, jQuery is used in one of the test cases (Jquery promise
). The $.ajax()
method returns a Deferred object, which can be used to chain methods like .done()
, .fail()
, and .always()
. This allows for easy handling of asynchronous operations and error handling.
Special JS features
There are no special JavaScript features or syntax mentioned in the benchmark. It's focused on comparing two approaches using existing JavaScript concepts.
Other alternatives
If you're interested in exploring alternative approaches, here are a few options:
es6-promise
library.Keep in mind that these alternatives may require additional setup or learning, but they can provide different trade-offs and benefits depending on your specific use case.