Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

throughput.js 1.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  1. const miss = require('mississippi');
  2. const util = require('util');
  3. function throughput(name, bs) {
  4. if (!bs) bs = 10000;
  5. process.stderr.write(name + ':');
  6. return {
  7. start: process.hrtime(),
  8. nrecs: 0,
  9. advance: function() {
  10. this.nrecs += 1;
  11. if (this.nrecs % bs == 0) {
  12. this.print();
  13. }
  14. },
  15. print: function(final) {
  16. var now = process.hrtime(this.start);
  17. var ftime = now[0] + now[1] * 1.0e-9;
  18. process.stderr.write("\r%s: processed %d records in %ss (%s recs/s)",
  19. name, this.nrecs, ftime.toFixed(3), (this.nrecs / ftime).toFixed(0));
  20. if (final) {
  21. process.stderr.write('\n');
  22. }
  23. }
  24. };
  25. }
  26. module.exports = throughput;
  27. module.exports.stream = function(name, bs) {
  28. let tp = throughput(name, bs);
  29. return miss.through.obj((chunk, enc, cb) => {
  30. tp.advance();
  31. cb(null, chunk);
  32. }, (cb) => {
  33. tp.print(true);
  34. cb();
  35. });
  36. };
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...