-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
746c38c
commit d78931b
Showing
15 changed files
with
446 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# js-spt | ||
|
||
## Description | ||
|
||
JS-SPT is a javascript Structure Performance Test designed to validate which data structure takes the least amount of time to handle a set of operations. This project was designed to help guide other projects and their data structures by demonstrating real world performance differences between each data structuring method in live loops. | ||
|
||
## Installation | ||
|
||
JS-SPT is prebuilt, and contains a webpage example as well as a NodeJS example. If you would like to rebiuld the bundled files, you will need to install the dev-dependencies via npm using the command `npm install`. | ||
|
||
## Usage | ||
|
||
### Building | ||
|
||
To build the project, simply run the following command: `npm run build`. This will build a **spt.js** *UMD* file as well as a **spt.module.js** *ES6* file. | ||
|
||
If you would like to actively modify and rebuild on `/src/**` change, run the following command: `npm run watch`. This will build the same two files mentioned above. | ||
|
||
### Examples | ||
|
||
To run the NodeJS example, simply run the command `npm start` from the projects root directory. This will run the application using the default controlled variables: | ||
* 50 Trials | ||
* 1000000 Operations per Trial | ||
* An Array, Object, and Class Structure | ||
|
||
To run the Web Example, navigate via your file explorer to [/examples/](https://github.com/InteractiveTimmy/js-spt/tree/master/examples) and load the [./index.html](https://github.com/InteractiveTimmy/js-spt/blob/master/examples/index.html) file into your favorite browser. The example will contain a form for customizing the controls for the test as well as some instructional information in regards to usage. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,107 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.ECS = factory()); | ||
}(this, (function () { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.SPT = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
|
||
var spt = { }; | ||
class StructClass | ||
{ | ||
constructor ( ) | ||
{ | ||
this.data = new Float32Array( [ | ||
Math.random( ), | ||
Math.random( ), | ||
Math.random( ) | ||
] ); | ||
} | ||
|
||
return spt; | ||
operate ( ) | ||
{ | ||
this.data[0] = Math.random( ), | ||
this.data[1] = Math.random( ), | ||
this.data[2] = Math.random( ); | ||
} | ||
} | ||
|
||
const StructObject = { | ||
create: ( ) => { | ||
return { | ||
data: new Float32Array( [ | ||
Math.random( ), | ||
Math.random( ), | ||
Math.random( ) | ||
] ) | ||
}; | ||
}, | ||
operate: ( struct ) => { | ||
struct.data[0] = Math.random( ); | ||
struct.data[1] = Math.random( ); | ||
struct.data[2] = Math.random( ); | ||
} | ||
}; | ||
|
||
const StructArray = { | ||
create: ( ) => { | ||
return new Float32Array( [ | ||
Math.random( ), | ||
Math.random( ), | ||
Math.random( ) | ||
] ); | ||
}, | ||
operate: ( struct ) => { | ||
struct[0] = Math.random( ); | ||
struct[1] = Math.random( ); | ||
struct[2] = Math.random( ); | ||
} | ||
}; | ||
|
||
class Trial | ||
{ | ||
constructor ( name, struct, type ) | ||
{ | ||
this.name = name; | ||
this.operate = ( ) => { console.log( 'hello' ); }; | ||
|
||
this.begin = null; | ||
this.end = null; | ||
this.delta = null; | ||
|
||
this.data = [ ]; | ||
|
||
this.mean = 0; | ||
|
||
if ( type === 'class' ) | ||
{ | ||
this.struct = new struct( ); | ||
this.operate = ( ) => { this.struct.operate( ); }; | ||
} | ||
else if ( type === 'object' ) | ||
{ | ||
this.struct = struct.create( ); | ||
this.operate = ( ) => { struct.operate( this.struct ); }; | ||
} | ||
else if ( type === 'array' ) | ||
{ | ||
this.struct = struct.create( ); | ||
this.operate = ( ) => { struct.operate( this.struct ); }; | ||
} | ||
} | ||
} | ||
|
||
class Target | ||
{ | ||
constructor ( ) | ||
{ | ||
|
||
} | ||
} | ||
|
||
exports.StructClass = StructClass; | ||
exports.StructObject = StructObject; | ||
exports.StructArray = StructArray; | ||
exports.Trial = Trial; | ||
exports.Target = Target; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
}))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,93 @@ | ||
var spt = { }; | ||
class StructClass | ||
{ | ||
constructor ( ) | ||
{ | ||
this.data = new Float32Array( [ | ||
Math.random( ), | ||
Math.random( ), | ||
Math.random( ) | ||
] ); | ||
} | ||
|
||
export default spt; | ||
operate ( ) | ||
{ | ||
this.data[0] = Math.random( ), | ||
this.data[1] = Math.random( ), | ||
this.data[2] = Math.random( ); | ||
} | ||
} | ||
|
||
const StructObject = { | ||
create: ( ) => { | ||
return { | ||
data: new Float32Array( [ | ||
Math.random( ), | ||
Math.random( ), | ||
Math.random( ) | ||
] ) | ||
}; | ||
}, | ||
operate: ( struct ) => { | ||
struct.data[0] = Math.random( ); | ||
struct.data[1] = Math.random( ); | ||
struct.data[2] = Math.random( ); | ||
} | ||
}; | ||
|
||
const StructArray = { | ||
create: ( ) => { | ||
return new Float32Array( [ | ||
Math.random( ), | ||
Math.random( ), | ||
Math.random( ) | ||
] ); | ||
}, | ||
operate: ( struct ) => { | ||
struct[0] = Math.random( ); | ||
struct[1] = Math.random( ); | ||
struct[2] = Math.random( ); | ||
} | ||
}; | ||
|
||
class Trial | ||
{ | ||
constructor ( name, struct, type ) | ||
{ | ||
this.name = name; | ||
this.operate = ( ) => { console.log( 'hello' ); }; | ||
|
||
this.begin = null; | ||
this.end = null; | ||
this.delta = null; | ||
|
||
this.data = [ ]; | ||
|
||
this.mean = 0; | ||
|
||
if ( type === 'class' ) | ||
{ | ||
this.struct = new struct( ); | ||
this.operate = ( ) => { this.struct.operate( ); }; | ||
} | ||
else if ( type === 'object' ) | ||
{ | ||
this.struct = struct.create( ); | ||
this.operate = ( ) => { struct.operate( this.struct ); }; | ||
} | ||
else if ( type === 'array' ) | ||
{ | ||
this.struct = struct.create( ); | ||
this.operate = ( ) => { struct.operate( this.struct ); }; | ||
} | ||
} | ||
} | ||
|
||
class Target | ||
{ | ||
constructor ( ) | ||
{ | ||
|
||
} | ||
} | ||
|
||
export { StructClass, StructObject, StructArray, Trial, Target }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,64 @@ | ||
// TODO | ||
'use strict'; | ||
|
||
let SPT; | ||
let instanceType; | ||
let target; | ||
|
||
try | ||
{ | ||
SPT = window.SPT; | ||
instanceType = 'browser'; | ||
} | ||
catch | ||
{ | ||
SPT = require( '../build/spt.js' ); | ||
instanceType = 'node' | ||
} | ||
|
||
console.log( `${instanceType} instance detected` ); | ||
|
||
let controls = { }; | ||
let trials = [ ]; | ||
|
||
function init ( ) | ||
{ | ||
controls.operations = 1000000; | ||
controls.trials = 50; | ||
|
||
trials.push( ...[ | ||
new SPT.Trial( 'class', SPT.StructClass, 'class' ), | ||
new SPT.Trial( 'object', SPT.StructObject, 'object' ), | ||
new SPT.Trial( 'array', SPT.StructArray, 'array' ) | ||
] ); | ||
|
||
start( ); | ||
} | ||
|
||
function start ( ) | ||
{ | ||
trials.forEach( trial => { | ||
for ( let x = 0; x < controls.trials; x++ ) | ||
{ | ||
trial.begin = Date.now( ); | ||
|
||
for ( let y = 0; y < controls.operations; y++ ) | ||
{ trial.operate( ); } | ||
|
||
trial.end = Date.now( ); | ||
trial.delta = trial.end - trial.begin; | ||
|
||
trial.data.push( trial.delta ); | ||
} | ||
|
||
trial.data.forEach( item => { | ||
trial.mean += item; | ||
} ); | ||
|
||
trial.mean /= trial.data.length; | ||
|
||
console.log( `${trial.name} had an average trial delta of ${trial.mean}ms` ); | ||
} ); | ||
} | ||
|
||
if ( instanceType === 'node' ) | ||
{ init( ); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as Trial } from './trial.js'; | ||
export { default as Target } from './target.js'; |
Oops, something went wrong.