5 ms·
Show HN: Sorting 50,000-element array in web browser using HTML5 web worker
- udfalkso 12y agoThis is neat, thanks. It would be better if the progress bar actually showed progress. A simple loading spinner gif would be better if that's all the progress bar really is in this case. I ran this on my phone earlier and wasn't sure if anything was actually happening because it took too long, and I gave up.
- afshinmeh 12y agoOw thanks :-) The reason I used progress-bar is to show the busy time of the browser while performing the action.
- TheLoneWolfling 12y ago...with bubble sort. Might want to mention that in the title.
- Kiro 12y agoI don't see how the algorithm is relevant here.
- mackwic 12y agoIt quite easy in fact: before going asynchronous, people should learn datastructures and algorithms adapted to what they want to do. It's wiser to limit the work your CPU has to do rather than hide this work behind high-level non-deterministic structures like WebWorkers like no work is done. Don't get me wrong, I'm not saying that WebWorker are useless. I just say that really costly operations are rare if you know your DS and complexities. Oh, by the way, you usually don't have to implement theses datastructures yourself. Even javascripts have [collections](http://www.collectionsjs.com/ http://www.collectionsjs.com/).
- TheLoneWolfling 12y agoBecause with a half-decent sorting algorithm you wouldn't need to use multithreading for this? On my machine with that particular 50k length array it takes 7ms if I just do "a.sort();".
- mackwic 12y agoHey ! Bubble sort can be a descent algorithm when you know when and how to use it ! After all, it is the fastest sorting algorithm when your collection is already sorted ! Moreover, it has very nice properties which make it suitable for a lot of concurrent operations.
- TheLoneWolfling 12y agoInsertion sort is faster for already-sorted data. (Note: I am not advocating to use insertion sort!)
- afshinmeh 12y agoIs it important?
- TheLoneWolfling 12y agoYes. When advocating using a new tech (or "new", as the case may be), one should find an example where the new tech is truly the best solution. (And if there is no such example, then I wonder why you are advocating it) If they had used a half-decent sorting algorithm (say... sort(), which on the array they give runs an absurdly short length of time) they wouldn't need to use web workers for this. There are all sorts of things where web workers are useful and better than alternatives. This is not one of them.
- lawl 12y agoNot meaning to offend you, but... what's the point of this submission? Webworkers have been here for a while now...
- afshinmeh 12y agoTo show the difference between performing a time/resource consuming action on web browsers with web workers and without it. Excuse me if you didn't find it useful.