MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

improve hex_digit lookup performance

+28 -19
+21 -4
examples/spec/run.js
··· 22 22 let filesPassed = 0; 23 23 let filesFailed = 0; 24 24 25 + const fileTimes = []; 26 + 25 27 console.log(`\n${BOLD}${CYAN}Running ${files.length} spec files...${RESET}\n`); 28 + 29 + const totalStart = performance.now(); 26 30 27 31 for (const file of files) { 28 32 const filePath = path.join(specDir, file); 29 33 const name = path.basename(file, '.js'); 30 34 35 + const start = performance.now(); 31 36 try { 32 37 const result = $`./build/ant ${filePath}`; 38 + const elapsed = performance.now() - start; 33 39 const output = result.text(); 34 40 console.log(output); 35 41 ··· 40 46 if (failedMatch) totalFailed += parseInt(failedMatch[1], 10); 41 47 42 48 if (result.exitCode === 0) { 43 - console.log(`${GREEN}โœ“${RESET} ${name}\n`); 49 + console.log(`${GREEN}โœ“${RESET} ${name} ${DIM}(${elapsed.toFixed(0)}ms)${RESET}\n`); 44 50 filesPassed++; 45 51 } else { 46 - console.log(`${RED}โœ—${RESET} ${name}\n`); 52 + console.log(`${RED}โœ—${RESET} ${name} ${DIM}(${elapsed.toFixed(0)}ms)${RESET}\n`); 47 53 filesFailed++; 48 54 } 55 + fileTimes.push({ name, elapsed }); 49 56 } catch (e) { 50 - console.log(`${RED}โœ—${RESET} ${name} ${DIM}(error)${RESET}\n`); 57 + const elapsed = performance.now() - start; 58 + console.log(`${RED}โœ—${RESET} ${name} ${DIM}(error, ${elapsed.toFixed(0)}ms)${RESET}\n`); 51 59 filesFailed++; 60 + fileTimes.push({ name, elapsed }); 52 61 } 53 62 } 54 63 64 + const totalElapsed = performance.now() - totalStart; 65 + 55 66 console.log(`\n${BOLD}Results:${RESET}`); 56 67 console.log(` ${GREEN}${totalPassed} tests passed${RESET}`); 57 68 console.log(` ${RED}${totalFailed} tests failed${RESET}`); 58 69 console.log(` ${GREEN}${filesPassed} files passed${RESET}`); 59 - console.log(` ${RED}${filesFailed} files failed${RESET}\n`); 70 + console.log(` ${RED}${filesFailed} files failed${RESET}`); 71 + 72 + console.log(`\n${BOLD}Timing:${RESET}`); 73 + for (const { name, elapsed } of fileTimes) { 74 + console.log(` ${DIM}${name.padEnd(30)}${RESET} ${elapsed.toFixed(0)}ms`); 75 + } 76 + console.log(`\n ${BOLD}Total${RESET}${' '.padEnd(26)}${totalElapsed.toFixed(0)}ms\n`); 60 77 console.log(`${PINK}Welcome to ES6!${RESET}`); 61 78 62 79 process.exit(totalFailed > 0 ? 1 : 0);
-11
examples/test262/index.js
··· 102 102 const lines = []; 103 103 104 104 if (state.mode === 'browse') { 105 - const headerWidth = Math.min(cols, 68); 106 - lines.push(`${c.bold}${c.blue}${'โ•'.repeat(headerWidth)}${c.reset}`); 107 - lines.push(`${c.bold}${c.blue} Test262 Results Visualizer${c.reset}`); 108 - lines.push(`${c.bold}${c.blue}${'โ•'.repeat(headerWidth)}${c.reset}`); 109 - lines.push(''); 110 - 111 105 const rateColor = stats.rate >= 80 ? c.green : stats.rate >= 50 ? c.yellow : c.red; 112 106 lines.push( 113 107 `${c.bold}Total:${c.reset} ${stats.total} ${c.green}Pass:${c.reset} ${stats.passed} ${c.red}Fail:${c.reset} ${stats.failed} ${rateColor}${stats.rate}%${c.reset}` ··· 194 188 lines.push(`${c.dim}s browse ยท q quit${c.reset}`); 195 189 } else if (state.mode === 'memory') { 196 190 const mem = Ant.stats(); 197 - const headerWidth = Math.min(cols, 68); 198 - lines.push(`${c.bold}${c.blue}${'โ•'.repeat(headerWidth)}${c.reset}`); 199 - lines.push(`${c.bold} Memory Usage${c.reset}`); 200 - lines.push(`${c.bold}${c.blue}${'โ•'.repeat(headerWidth)}${c.reset}`); 201 - lines.push(''); 202 191 203 192 lines.push(`${c.cyan}Arena${c.reset}`); 204 193 lines.push(` Used: ${c.bold}${fmt(mem.arenaUsed)}${c.reset}`);
+7 -4
src/utils.c
··· 12 12 }; 13 13 14 14 int hex_digit(char c) { 15 - if (c >= '0' && c <= '9') return c - '0'; 16 - if (c >= 'A' && c <= 'F') return c - 'A' + 10; 17 - if (c >= 'a' && c <= 'f') return c - 'a' + 10; 18 - return -1; 15 + static const int8_t lookup[256] = { 16 + ['0']=0, ['1']=1, ['2']=2, ['3']=3, ['4']=4, ['5']=5, ['6']=6, ['7']=7, ['8']=8, ['9']=9, 17 + ['a']=10, ['b']=11, ['c']=12, ['d']=13, ['e']=14, ['f']=15, 18 + ['A']=10, ['B']=11, ['C']=12, ['D']=13, ['E']=14, ['F']=15, 19 + }; 20 + int8_t val = lookup[(unsigned char)c]; 21 + return val ? val : (c == '0' ? 0 : -1); 19 22 } 20 23 21 24 uint64_t hash_key(const char *key, size_t len) {