austinksmith / hamsters.js Goto Github PK
View Code? Open in Web Editor NEW100% Vanilla Javascript Multithreading & Parallel Execution Library
Home Page: https://www.hamsters.io
License: Artistic License 2.0
100% Vanilla Javascript Multithreading & Parallel Execution Library
Home Page: https://www.hamsters.io
License: Artistic License 2.0
Issue identified preventing IE10 operation due to cross origin resource sharing restrictions, workaround in progress. This issue does not affect IE11.
Hello,
Trying the fourth test function under node.
However, I'm compiling from ES6, so I've switched the function
s to arrow functions:
import * as hamsters from 'hamsters.js'
//4 threads and let's aggregate our individual thread results into one final output
const pfunc = () => {
const params = { 'array': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] }
hamsters.run(params, () => {
const arr = params.array
arr.forEach((item) => {
rtn.data.push((item * 120) / 10)
})
},
(output) => output,
4, true)
}
const res = pfunc()
console.log("hamster res:", res)
This fails with the following error:
hamster res: undefined
/Volumes/Second/Chris/myprogram/node_modules/hamsters.js/src/es5/hamsters.js:653
self.rtn = {
^
ReferenceError: self is not defined
at null._onTimeout (/Volumes/Second/Chris/myprogram/node_modules/hamsters.js/src/es5/hamsters.js:653:7)
at Timer.listOnTimeout (timers.js:92:15)
real 0m0.082s
user 0m0.064s
sys 0m0.014s
This is using node v4.3.2 (for compatibility reasons).
Any clues? Thanks!
I have a page where I have 4 canvases displaying images and I currently use javascript timers to loop through images in a set and draw those images on the canvas. but the problem I have is that my timers are synchronous because Javascript is single threaded. so for my 4 canvases, my first canvas animates and then the second and so on. they're not animating concurrently.
I saw the examples for Hamsters.js and they're all modifying a variable but do they even modify the DOM as well?
It's fail?
http://www.hamsters.io/performance/
PC, Windows 10, Intel i5 6600k. Tested in chrome and nightly (firefox).
am using v4.1.2 its working i was thinking to update it to v5 i have downloaded v5 and replaced v4 files with it . but am getting error
Uncaught TypeError: _hamsters2.default.init is not a function
am using webpack 4 environment
i imported it like
import hamsters from './../../../node_modules/hamsters.js/build/hamsters.js';
the i have starting params
// init hamster
var startOptions = {
maxThreads: navigator.hardwareConcurrency,
cache: false,
debug: true,
persistence: false
};
hamsters.init(startOptions);
so wondering what need to be change for v5 , i go through wiki its installation it shows hamsters.init
windows 7
vanilla js , webpack 4.1
chrome v70
using your awesome library for a test drive.
##planted like this:
var hamsters = require('hamsters.js');
##used it like this:
var v = [{digit: 1, type: 'number'}, {digit: 1, type: 'number'}, {digit: 1, type: 'number'}, {digit: 1, type: 'number'}];
var params = {
array: v;
threads: 4
};
hamsters.run(params, function() {
console.log("I ran")
});
and chrome console says:
Hamsters.js v5.1.1 Error: undefined @ 1529048722217
##using
Angular 5
Google Chrome Version 66.0.3359.181 (Official Build) (64-bit)
Thanks ๐
Hello
I'm getting error message using hamsters and react-native-threads. I'm able to use both but still get typeError.
What version of the library are you using?
react-native: 0.55.2
react-native-threads: 0.0.13
hamsters: 5.1.1
What operating system are you seeing the issue on?
Android / React-native
I'm able to call up the worker and it does it's job but I get this typeError message, so I'm not sure if I'm benefitting from using hamsters or not.
Hamsters.js v5.1.1 Info: Preparing the hamster wheels & readying hamsters @ 1542796747783
hamsters.node.min.js:1 Hamsters.js v5.1.1 Info: 16 Logical Threads Detected, Spawning 16 Hamsters @ 1542796747784
CameraScreen.js:547 TypeError: f.default.SharedWorker is not a constructor
at e.value (hamsters.node.min.js:1)
at e.value (hamsters.node.min.js:1)
at e.value [as init] (hamsters.node.min.js:1)
at CameraScreen.js:540
at tryCallOne (core.js:37)
at core.js:123
at JSTimers.js:295
at _callTimer (JSTimers.js:152)
at _callImmediatesPass (JSTimers.js:200)
at Object.callImmediates (JSTimers.js:464)
The code I use to call upp the hamster is:
hamsters.init({
maxThreads: 16,
Worker: this.workerThread.postMessage( workerMessage )
})
Is there some better way of using react-native-threads and hamsters together ?
Hello !
It is impossible to initialize my pool of threads
This is my code:
let startOptions = {
maxThreads: 2,
cache: false,
debug: true,
persistence: false,
};
hamsters.init(startOptions);
let params = {
array: [1,2,3,4,5,6,7,8,9,10],
animal: 'Hamster',
};
hamsters.run(params, function() {
if(params.animal === 'Hamster') {
rtn.data.push('Hamsters are awesome');
}
}, function(result) {
console.log(result);
});
4.1.3
tvOS
Error Message:
ExceptionsManager.js:63 Worker is not defined
handleException @ ExceptionsManager.js:63
handleError @ InitializeCore.js:125
reportFatalError @ error-guard.js:44
__guard @ MessageQueue.js:220
callFunctionReturnFlushedQueue @ MessageQueue.js:100
(anonymous) @ debuggerWorker.js:71
Windows: 10
Node: v10.14.2
hamsters.js: 5.1.2
webworker-threads: 0.7.17
const Worker = require('webworker-threads').Worker
const hamsters = require('hamsters.js')
hamsters.init({
Worker: Worker
})
const params = {
array: [1, 2, 3, 4],
threads: 1,
aggregate: true
}
hamsters.promise(params, () => {
for (let i=0; i<params.array.length; i++) {
rtn.data.push(params.array[i] * 2)
}
}).then( (results) => {
console.log(results)
}).catch( (error) => {
console.error(error)
})
Console -> Hamsters.js v5.1.2 Info: Hamsters.js v5.1.2 initialized using up to 4 threads. @ 1545047704894
and freezes...
What am i doing wrong?
Thank you for your interest in the library, I am opening this issue ticket to try to get a better grasp from the community for what use cases they have for the library and what features they think would be useful to add to the library.
If you are currently using the library please respond to this with the format below and let me know what you think, thank you!
Thank you for the wonderful library.
For several days now I have been trying to try working with promises and getting an error ...
Help me please :)
Windows 10
Node v10.14.0
Hamsters 5.1.1
Code ->
const Worker = require('workerpool').Worker
const hamsters = require('hamsters.js')
hamsters.init({
Worker: Worker
})
var params = {
array: [1, 2, 3, 4, 5, 6, 7, 8],
threads: 1,
aggregate: true
}
var method = function() {
for(var i = 0; i < params.array.length; i++) {
rtn.data.push(Math.sqrt(params.array[i]))
}
}
hamsters.promise(params, method)
.then(function(results) {
console.log(results)
}).catch(function(error) {
console.error(error)
})
Or ->
hamsters.promise(params, function() {
for (let i=0; i<params.array; i++) {
rtn.data.push(params.array[i] * 2)
}
})
.then( (results) => {
console.log(results)
}).catch( (error) => {
console.error(error)
});
Error ->
ReferenceError: scaffold is not defined
at F:\X-project-inf\node_modules\hamsters.js\build\hamsters.node.min.js:1:19131
at new Promise (<anonymous>)
at e.value [as promise] (F:\X-project-Inf\node_modules\hamsters.js\build\hamsters.node.min.js:1:19029) at Object.<anonymous> (F:\X-project-Inf\src\test.js:16:10) at Module._compile (internal/modules/cjs/loader.js:688:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
Issue: Current hashing algorithm is slow, session storage 5mb limit introduces performance drawbacks.
Possible Solution: Use in memory caching, possibly optimize hash function
Hi, I am trying to get this library up and running to help with some calculations I am going to be running but I keep getting an undefined error when I try and call hamsters.run.
I have an array of an array of objects, that are nested via d3 prior having it passed into hamsters, I am not sure if that is causing the issue or not, which I would hope not since this is a fairly basic use case, nothing too fancy...
and in hamsters, I get a red underline at:
Here is the actual code:
this.getScores = function (data) {
//we are going to utilize a library called hamsters for multithreading support
let params = {
myParams: data,
threads: 4
};
hamsters.run(params, function () {
for (var i = 0; i < params.myParams; i++) {
//now we do the calculations in here
console.log(params);
};
});
Any help would be appreciated, I would like to have multithreading support for this project as there are quite a lot of calculations that are going to be needed
Issue: Library is not supporting as a Node module.
Its working only for html file.
I request to make one standard file/library for nodejs users.
Would it be possible to publish the library to npm?
Hi, I have a RN application and just want to try parallel programming using hamsters.js. First, I created a demo app to try it with a worker, namely https://github.com/fabriciovergal/react-native-workers. however I am getting a strange error,
What version of the library --> 4.2.0
What operating system are you seeing the issue on? --> Windows
Which platform (and or) browser are you seeing the issue on? React Native on andorid
What is the version of the platform (and or) browser you are seeing the issue on? --> RN 48.0
The code that I wrote simply (i saw this in how the library manages your data) :
initHamsters(){
const startOptions = {
maxThreads: 4,
cache: false,
debug: false,
persistence: false,
Worker: Worker
};
hamsters.init(startOptions);
const params = {
array: [1,2,3,4,5,6,7,8,9,10],
animal: 'Hamster',
};
hamsters.run(params, function() {
if(params.animal === 'Hamster') {
rtn.data.push('Hamsters are awesome');
}
}, function(result) {
console.log(result);
});
}
I have to say that there is not so many worker libraries availalbler for react native, and the one that I found was working, i tried it. However, it has some requirements like using two ports and having index.worker.js and I didnt provide them to run this code. the error is like this :
and as I understand this is a react native error, which doesnt allow to use this library and Worker library.
Any ideas?
Thank you for using Hamsters.js! In order to best assist you please follow the guidelines laid out below as they will help significantly in resolving your issues. Tickets that do not follow the provided issue template have less than satisfactory information to resolve the problem reported and will therefore not receive priority support.
Attitude goes a long way, while we do our best to ensure the library is problem free it is a very complicated library that encapsulates many features all while trying to support as many platforms as possible. Inevitably some issues may prop up from time to time, patience, understanding, and collaboration are the best ways to resolve bugs in a timely manner.
This will help narrow down the issue you are facing to a specific release of the library, as your issue may be resolved in previous or latter releases.
Feature support can vary wildly and any issues you are facing may be exclusive to a specific operating system or even a specific version of an operating system.
Some issues may be isolated to specific environments or systems, an issue you are facing in Node.js for example may not be applicable to React Native.
Feature support can vary wildly and any issues you are facing may be exclusive to a specific browser or framework and specific versions of a browser or framework.
Being able to reproduce an issue directly goes a very long way towards debugging issues with the library, having example logic is probably the most important step you can take towards helping us resolve your issues.
handleHamster = () => {
var params = {
array:[0,1,2,3,4,5,6,7,8,9]
};
hamsters.run(params, function() {
var arr = params.array;
arr.forEach(function(item) {
console.warn('calllll', item)
rtn.data.push((item * 120)/10);
});
}, function(output) {
console.warn('output', output)
return output;
}, 2, false);
}
here rtn not find.
I am using version :
"hamsters.js": "^4.2.1",
"react": "16.2.0",
"react-native": "0.52.1",
"react-native-threads": "0.0.10",
For some reason when updating from 4.1.1 to 4.1.2, In 4.1.1. and running the same code with hamsters.js in node.js and in browser (Angular v4) app, both places code worked fine. However, with 4.1.2, seems browser does not spin up threads anymore.
Hamsters.run always tries to convert a given array to a typed array... even if it is not!. The problem is, that Hamsters.run assigns dataType = "na" if no data type has been given.
However, feedHamster uses transferables when dataType is truthy (what now always is the case).
It's slightly odd to see global scope injected scope for params
and rtn
variables. In my opinion, it would be more readable to see global variables removed and possibly separate the notions of hamster creation and task execution, like so:
var twoHamsters = Hamsters.spawn({
count: 2,
task: function (slice) {
return slice.map(function (element) { return (element * 120) / 10; });
},
onSliceComplete: function (sliceResult) {
console.log(sliceResult);
},
onTaskComplete: function (taskResult) {
console.log(taskResult);
}
});
twoHamsters.feed([1,2,3,4,5,6,7,8,9,0]);
hi am processing canvas large data so to speedup things am trying to use hamsters for the first time
so my question is that my outside functions are not accessible within hamsters.run
example
this.testfun = function(val){
// do something and return
};
hamsters.run(params, function() {
// my code calling function testfun but it giver error undefined.
}, function(output) {
console.log(output);
}, hamsters.maxThreads, true);
thanks
latest version of library
windows 7
Core JS (Vanilla)
Am on Firefox browser , using core js with html5 canvas doing some heavy image processing so i mostly use hamster.js to split the image portion for processing between threads , recently i have started getting error out of memory and object could not be cloned , so i was wondering how overcome this memory issue , also any idea to allocate more memory in browser to JS so that out of memory issue not occur as i have 16GB RAM
Error Hamster #0: Line 0 in : uncaught exception: out of memory hamsters.js:607:5
onerror /js/vendor/hamsters/hamsters.js:607:5
uncaught exception: out of memory
Error Hamster #0: Line 0 in : DataCloneError: The object could not be cloned. hamsters.js:607:5
onerror /js/vendor/hamsters/hamsters.js:607:5
DataCloneError: The object could not be cloned.
Hi, I have a RN application and just want to try parallel programming using hamsters.js. First, I created a demo app to try the library. however I am getting a strange error,
What version of the library --> 4.2.0
What operating system are you seeing the issue on? --> Windows
Which platform (and or) browser are you seeing the issue on? React Native on andorid
What is the version of the platform (and or) browser you are seeing the issue on? --> RN 48.0
The ERROR : TrasnformError: C//Users.. //node_modules//hamsters.js//build//hamsters.js : Couldn't find the preset 'es2015' relative to the directory C//Users//.. node_modules//hamsters.js
thanks for the amazing lib :) i was wondering when the new version will be released as i have noticed its logger is improved with current latest version i have bit hard time with debugging as recently i have encountered error when i have started using hamster along webpacks
Error Hamster #0: Line 431 in : Uncaught ReferenceError: _slicedToArray is not defined
onerror @ hamsters.js:610
In a loop Hamsters seems to take a vector/array and split it across the threads available but does not aggregate the results to one final output - the output is per thread ONLY. For instance, if you multiply an array like [1,2,3,4,5] with the scalar 2, the array is split into two threads (assuming a duo-core machine) with data [1,2, 3] and [4,5] respectively, which ends up with two separate arrays... i.e. [2,4,6] and [8,10] AND NOT [2,4,6,8,10] as I expected. See code below.
How can we AGGREGATE MULTIPLE threads output BACK INTO ONE array? BUT more peculiarly, ONLY the first (or one) thread actually returns the expected result, the other thread(s) do not seem to always return correct results - unless ONLY if threads is set to 1, which defeats the value of using multiple cores/parallelism. It doesn't matter even if I use tools (hamsters.tools.loop) the results returned are wrong. Is this a bug?
var matrix = [
[1,2,3,4,5],
[1,2,3,4,5]
];
var i;
for (i = 0; i < matrix.length; i += 1) {
try {
var j, dotprod = 0, matrix_row = matrix[i];
for (j = 0; j < matrix_row.length; j += 1) {
dotprod += (matrix_row[j] * 2);
}
console.log("Vanilla-output:" + dotprod);
var params = {'array': matrix_row};
hamsters.run(params, function () {
var arr = params.array;
var dotprod = [];
arr.forEach(function (item) {
dotprod.push(item * item);
});
console.log("each-thread:" + dotprod);
rtn.data = dotprod;
}, function (results) {
var output = 0;
console.log("Hamsters-aggregation:" + results);
results.forEach(function (item) {
output += item;
});
console.log("Hamsters-summation:" + output);
}, hamsters.maxThreads, true, 'Float32');
} catch (err) {
console.log(err);
}
}
(sorry I'm not following the issue template, but the questions there didn't make sense to write down on this page)
I just started reading about the library and would like to see some example code. Now I'll dig through this repo instead.
I thought that the project examples should have the example's source code, or a link to it. It would make the website better!
Cheers!
so i have replaced v4.2 with v5.1.1 and i noticed few new things one is "data" key in rtn return object earlier it was just 0 index i fixed by adding ['data'] in code to extract the thread data which is pushed it index 0 for single thread , however the another strange thing i noticed when we create multiple threads then rtn push data on index which is same thread number , i wonder it will be good if all threads push its data index 0 is v4.2.2 was doing or any fix for it
v 5.1.1
windows 7
apache , chrome v70
chrome v70
Hello, I need some help with my code.
Problem:
I adapted the code to the library's form and when I run it the problem is the conditional run first and then the threads. The correct way is when threads is finished pass the next code line which what is the conditional.
See the code in Pastebin website
Click here to view the Image
Am I doing wrong something?
Hope help me. (sorry for my english)
Ima newbie with web workers.
Issue: Try catch causes functions containing them not to be optimized by the runtime
Possible Solution: Move try catch outside of execution logic precompute variable to determine support before hand
Hello. I trying search package "Hamsters", "WebHamsters", but Visual Studio 2015 (JavaScript Project, Bower packages, all right) can not found this library. Try to fix this issue. Also, can not found in preview versions.
Hello. Have you support for these features? Supports in chrome (canary, with flags) and firefox.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics
Something kind of this https://jsfiddle.net/m82v751c/3/
"hamsters.js": "^5.0.0" + "react-native-threads": "^0.0.10"
MacOS
React-Native
"react": "^16.3.0-alpha.1",
"react-native": "0.54.0",
Trying to run the code described on your wiki, within a brand new sample app created with
Step 1
react-native init HamstersTest
Step 2
Babel es2015 dependencies
Step 3
import { Thread } from 'react-native-threads';
import hamsters from 'hamsters.js';
...
hamsters.init({
Worker: Thread
});
...
executeHamsters() {
var params = {
array: [1, 2, 3, 4],
threads: 4
};
hamsters.run(params, function() {
for(var i = 0; i < params.array; i++) {
rtn.data.push(params.array[i] * 4);
}
}, function(results) {
console.debug('results', results);
});
}
How about adding support for Promises. Many asynchronous libraries now offer both callbacks and Promises. I would love to be able to use Hamsters.js with async/await.
On my machine, when running (v4.1.1) in Edge "navigator.hardwareConcurrency" is undefined but "navigator" is defined.
During init if I don't explicitly specify "maxThreads" hamsters crashes.
I.e. We get in here and maxThreads is set to undefined:
function setupHamstersEnvironment(onSuccess) {
....
if(typeof navigator !== 'undefined') {
hamsters.maxThreads = navigator.hardwareConcurrency;
}
....
}
There should probably be an additional test, something like this:
function setupHamstersEnvironment(onSuccess) {
....
if(typeof navigator !== 'undefined' && typeof navigator.hardwareConcurrency !== 'undefined') {
hamsters.maxThreads = navigator.hardwareConcurrency;
}
....
}
I was trying to see how much performance gain I should expect from multi-thread my task. So I tried the test on the official site. But surprisingly, the result indicated that there was very little performance gain even on the 25.6 million cases.
I am aware of the Amdahls Law and Gustafson Law, but still cannot figure out a reasonable explanation. Anyone have some ideas?
I've got a situation where I've got about 400mb of output data in Float64Arrays. This is retained and not GC's between runs.
I've put together a very simple fix for this but haven't tested with memoisation.
You can only install version 3.7 from NPM.
I'm trying to run the example code as such:
const hamsters = require('hamsters.js');
hamsters.init({
maxThreads: 10,
cache: false,
debug: false,
persistence: true,
});
const foo = () => {
var params = {
'array':[0,1,2,3,4,5,6,7,8,9]
};
hamsters.run(params, function() {
var arr = params.array;
arr.forEach(function(item) {
rtn.data.push((item * 120)/10);
});
}, function(output) {
return output;
});
};
foo();
but got error:
node_modules/hamsters.js/src/es5/hamsters.js:124
hamsters.wheel.hamsters.push(new Worker(hamsters.wheel.uri));
^
ReferenceError: Worker is not defined
at spawnHamsters (node_modules/hamsters.js/src/es5/hamsters.js:124:44)
What version of the library are you using? 5.1
What operating system are you seeing the issue on? Windows 7
Which platform (and or) browser are you seeing the issue on? Chrome
What is the version of the platform (and or) browser you are seeing the issue on? Chrome 63/Angular JS 1.50
Example logic
I am trying to pass in Uint8Arrays and it hamsters.run and then gives me that error...
It appears I might be missing something? I have referenced the hamsters.js library properly as I set the hamsters.init and get it to run...
hamsters.init({
browser: true,
reactNative: false,
node: false,
maxThreads: 16,
debug: 'verbose'
});
and here is where I run hamsters:
var data = [];
var myProm;
for (var i = 0; i < 4; i++) {
let num = i + 1;
if (i === 3) {
user.readBinary(CVData.path + num + '.xlsb').then(function (response) {
data.push(new Uint8Array(response));
});
} else {
myProm = user.readBinary(CVData.path + num + '.xlsb').then(function (response) {
data.push(new Uint8Array(response));
});
}
}
//wait for the final promise to resolve
myProm.then(function () {
var params = {
array: data,
aggregate: true
};
hamsters.run(params, function () {
params.array.forEach(function (item) {
var workbook = XLSX.read(item, { type: "array" });
var myJSON = XLSX.utils.sheet_to_json(workbook.Sheets.Sheet1);
rtn.data.push(myJSON);
});
}, function (results) {
console.log(results);
});
});
Basically I want to pass in Uint8Arrays I am converting from ArrayBuffers I am getting from binary files I am loading in, use hamsters to do the processing work to turn it into a usable JSON object and then aggregate thees JSON objects into a single object with the results for each of the files. Is this possible and if so, what am I doing wrong?
Do you have some sort working example for this? I really do not understand the origin of your "rtn" variable and how outputs are passed back to the main thread.
function test(){
var params = {'array':[0,1,2,3,4,5,6,7,8,9]};
hamsters.run(params, function() {
for(var i = 2;i<params.array.length;i++)
{
params.array[i]= params.array[i-1]+params.array[i-2];
rtn.data.push(params.array[i]);
}
}, function(output) {
console.log(output)
return output;
}, 4 , true);
}
Thank you for using Hamsters.js! In order to best assist you please follow the guidelines laid out below as they will help significantly in resolving your issues. Tickets that do not follow the provided issue template have less than satisfactory information to resolve the problem reported and will therefore not receive priority support.
Attitude goes a long way, while we do our best to ensure the library is problem free it is a very complicated library that encapsulates many features all while trying to support as many platforms as possible. Inevitably some issues may prop up from time to time, patience, understanding, and collaboration are the best ways to resolve bugs in a timely manner.
This will help narrow down the issue you are facing to a specific release of the library, as your issue may be resolved in previous or latter releases.
Feature support can vary wildly and any issues you are facing may be exclusive to a specific operating system or even a specific version of an operating system.
Some issues may be isolated to specific environments or systems, an issue you are facing in Node.js for example may not be applicable to React Native.
Feature support can vary wildly and any issues you are facing may be exclusive to a specific browser or framework and specific versions of a browser or framework.
Being able to reproduce an issue directly goes a very long way towards debugging issues with the library, having example logic is probably the most important step you can take towards helping us resolve your issues.
Team,
Is there away we can send notifications (small payload, with processing info) from the worker threads back to the main thread? e.g. To possibly support providing progress data from threads that are spawned to the main thread? Maybe, allow the ability to pass in another callback for notifications.
Using [email protected]
, I was able to run the example code. However I don't think it's making any sense to me. Also since I'm not seeing the result I'm expecting, I don't think this library is working properly.
Suppose running this code:
const foo = () => {
var params = {
'array':[0,1,2,3,4,5,6,7,8,9]
};
hamsters.run(params, function() {
var arr = params.array;
arr.forEach(function(item) {
rtn.data.push((item * 120)/10);
});
}, function(output) {
console.log(output);
}, 10);
};
foo();
I was expecting the workload to be distributed among these 10 threads. But after some console logging, I see they are getting the exact same array and they are doing the exact same work, just now 10 times. How does that help? Maybe the example code just doesn't explain this but I was expecting either:
Could you help me understand how this library should be used? If you need an example, say we have a big array of size n
(n
> 10k) of positive integers and we are trying to find (x) => x * (x - 1) * (x - 2) * ... * 2 * 1
for every item in the array. Since the data items have no dependency on each other, ideally we could spawn n
threads where each one would grab one number and start calculating. Could you illustrate how this could be done with this library?
Thanks a lot.
Side note: Since params
and rtn
are special "internal" variables, why not pass them in this way so it's easier to understand?
hamsters.run(params, function(params, rtn) {
var arr = params.array;
arr.forEach(function(item) {
rtn.data.push((item * 120)/10);
});
}, function(output) {
console.log(output);
}, 10);
Cloned the repo, dev.
npm install
npm run test
OS: Windows 10.
Here is the resport.
https://pastebin.com/8AL6yaHQ
Also it does not build. Havent digged why yet.
It's caused by rm and cp commands, which does not exists in windows. Most of these issues might be fixed by using a more recent webpack version and a couple of plugins to move things around and delete/clean folders.
Cheers
I can't open www.hamsters.io/. Is it ok now?
A bug was discovered in transferrable object support in the most recent released version, the development branch resolves this issue but is not complete in regards to memoization yet. A new release will be out shortly that resolves all remaining discovered bugs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.