<!-- JStat -->
<script src="https://cdn.jsdelivr.net/jstat/latest/jstat.min.js"></script>
<!-- NumericJS -->
<script src="https://cdn.rawgit.com/sloisel/numeric/master/src/numeric.js"></script>
<!-- Math.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.9.0/math.min.js"></script>
var A = [[11, -1, 0], [-1, 12, -1], [0, -1, 11]],
B = [[87], [12] , [0]];
var Numeric_LUa = numeric.LU(A),
math_LUa = math.lup(A);
jStat.gauss_elimination(A, B);
numeric.solve(A, B);
numeric.LUsolve(Numeric_LUa, B);
math.lusolve(A, B);
math.lusolve(math_LUa, B);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
jStat | |
Numeric JS (uses LUsolve under the hood) | |
Numeric JS (LU Decomposed first) | |
math.js | |
math.js (LU Decomposed first) |
Test name | Executions per second |
---|---|
jStat | 2358601.8 Ops/sec |
Numeric JS (uses LUsolve under the hood) | 930884.4 Ops/sec |
Numeric JS (LU Decomposed first) | 1385989.8 Ops/sec |
math.js | 464471.1 Ops/sec |
math.js (LU Decomposed first) | 839937.2 Ops/sec |
Let's break down the provided benchmark definition and test cases.
Benchmark Definition:
The benchmark is designed to solve a system of linear equations using matrix operations. The script preparation code provides two matrices, A and B, which are used as input for the benchmarks. The Html Preparation Code includes links to external libraries: JStat (a statistical analysis library), NumericJS (a numerical computation library), and Math.js (a mathematical expression library).
Test Cases:
The benchmark compares four different approaches:
gaussElimination
function from the JStat library to solve the system of linear equations.solve
function from the NumericJS library to solve the system of linear equations. Note that this function is actually using an LU decomposition under the hood (more on this later).LU
function from the NumericJS library and then uses the LUsolve
function to solve the system of linear equations.lusolve
function from the Math.js library to solve the system of linear equations. Note that this function is also performing an LU decomposition (more on this later).Options Compared:
The benchmark is comparing four different approaches:
gauss_elimination
function vs. using a built-in solve
function with LU decomposition.LU
function and then solving the system of linear equations vs. using an existing implementation in the library.Pros and Cons:
Here are some pros and cons for each approach:
Libraries and Their Purpose:
gaussElimination
function for solving systems of linear equations.LU
, LUsolve
) and other matrix operations.lusolve
function for solving systems of linear equations using LU decomposition.Special JS Features or Syntax:
None mentioned in the provided benchmark definition.
Alternatives:
Other alternatives for solving systems of linear equations include:
Note that the choice of approach will depend on the specific requirements and constraints of your project.