Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

marky.es.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* global performance */
  2. var perf = typeof performance !== 'undefined' && performance;
  3. var nowForNode;
  4. {
  5. // implementation borrowed from:
  6. // https://github.com/myrne/performance-now/blob/6223a0d544bae1d5578dd7431f78b4ec7d65b15c/src/performance-now.coffee
  7. var hrtime = process.hrtime;
  8. var getNanoSeconds = function () {
  9. var hr = hrtime();
  10. return hr[0] * 1e9 + hr[1]
  11. };
  12. var loadTime = getNanoSeconds();
  13. nowForNode = function () { return ((getNanoSeconds() - loadTime) / 1e6); };
  14. }
  15. var now = nowForNode;
  16. function throwIfEmpty (name) {
  17. if (!name) {
  18. throw new Error('name must be non-empty')
  19. }
  20. }
  21. // simple binary sort insertion
  22. function insertSorted (arr, item) {
  23. var low = 0;
  24. var high = arr.length;
  25. var mid;
  26. while (low < high) {
  27. mid = (low + high) >>> 1; // like (num / 2) but faster
  28. if (arr[mid].startTime < item.startTime) {
  29. low = mid + 1;
  30. } else {
  31. high = mid;
  32. }
  33. }
  34. arr.splice(low, 0, item);
  35. }
  36. var mark;
  37. var stop;
  38. var getEntries;
  39. var clear;
  40. if (
  41. perf &&
  42. perf.mark &&
  43. perf.getEntriesByName &&
  44. perf.getEntriesByType &&
  45. perf.clearMeasures
  46. ) {
  47. mark = function (name) {
  48. throwIfEmpty(name);
  49. perf.mark(("start " + name));
  50. };
  51. stop = function (name) {
  52. throwIfEmpty(name);
  53. perf.mark(("end " + name));
  54. perf.measure(name, ("start " + name), ("end " + name));
  55. var entries = perf.getEntriesByName(name);
  56. return entries[entries.length - 1]
  57. };
  58. getEntries = function () { return perf.getEntriesByType('measure'); };
  59. clear = function () {
  60. perf.clearMarks();
  61. perf.clearMeasures();
  62. };
  63. } else {
  64. var marks = {};
  65. var entries = [];
  66. mark = function (name) {
  67. throwIfEmpty(name);
  68. var startTime = now();
  69. marks['$' + name] = startTime;
  70. };
  71. stop = function (name) {
  72. throwIfEmpty(name);
  73. var endTime = now();
  74. var startTime = marks['$' + name];
  75. if (!startTime) {
  76. throw new Error(("no known mark: " + name))
  77. }
  78. var entry = {
  79. startTime: startTime,
  80. name: name,
  81. duration: endTime - startTime,
  82. entryType: 'measure'
  83. };
  84. // per the spec this should be at least 150:
  85. // https://www.w3.org/TR/resource-timing-1/#extensions-performance-interface
  86. // we just have no limit, per Chrome and Edge's de-facto behavior
  87. insertSorted(entries, entry);
  88. return entry
  89. };
  90. getEntries = function () { return entries; };
  91. clear = function () {
  92. marks = {};
  93. entries = [];
  94. };
  95. }
  96. export { clear, getEntries, mark, stop };