|
2 | 2 | import { promises as fs } from 'fs'; |
3 | 3 | import * as github from '@actions/github'; |
4 | 4 | import { Config, ToolType } from './config'; |
| 5 | +import * as core from '@actions/core'; |
5 | 6 |
|
6 | 7 | export interface BenchmarkResult { |
7 | 8 | name: string; |
@@ -690,6 +691,93 @@ function extractLuauBenchmarkResult(output: string): BenchmarkResult[] { |
690 | 691 | return results; |
691 | 692 | } |
692 | 693 |
|
| 694 | +function parseTimeOutput(line: string): number | undefined { |
| 695 | + core.debug(`parse time ${line}`); |
| 696 | + const t = line.split('\t')[1]; |
| 697 | + if (t === undefined) return; |
| 698 | + const tparts = t.split('m'); |
| 699 | + |
| 700 | + core.debug(tparts[0]); |
| 701 | + if (tparts[1] === undefined || !tparts[1].endsWith('s')) return; |
| 702 | + return parseFloat(tparts[0]) * 60.0 + parseFloat(tparts[1].substring(-1)); |
| 703 | +} |
| 704 | +/* Expect to process text with the following structure: |
| 705 | +
|
| 706 | + $ time echo Hello there |
| 707 | + Hello there |
| 708 | +
|
| 709 | + real 0m0,100s |
| 710 | + user 0m0,020s |
| 711 | + sys 0m0,003s |
| 712 | + $ time echo Hello there |
| 713 | + Hello again |
| 714 | +
|
| 715 | + real 0m0,100s |
| 716 | + user 0m0,020s |
| 717 | + sys 0m0,003s |
| 718 | +
|
| 719 | + Into: |
| 720 | + [{"name": "real", |
| 721 | + "value": 0,1, |
| 722 | + "unit": "s", |
| 723 | + "extra": "testName: Hello there"}, |
| 724 | + ... |
| 725 | +*/ |
| 726 | +function extractTimeBenchmarkResult(output: string): BenchmarkResult[] { |
| 727 | + const lines = output.split(/\n/); |
| 728 | + const results: BenchmarkResult[] = []; |
| 729 | + let firstline = true; |
| 730 | + let name: string | undefined = undefined; |
| 731 | + |
| 732 | + for (const line of lines) { |
| 733 | + core.debug(line); |
| 734 | + if (firstline) { |
| 735 | + name = line; |
| 736 | + firstline = false; |
| 737 | + core.debug(`firstline: ${name}`); |
| 738 | + continue; |
| 739 | + } |
| 740 | + if (line.startsWith('real')) { |
| 741 | + const v = parseTimeOutput(line); |
| 742 | + core.debug(`v: ${v}`); |
| 743 | + if (v !== undefined) |
| 744 | + results.push({ |
| 745 | + extra: name, |
| 746 | + name: 'real', |
| 747 | + value: v, |
| 748 | + unit: 's', |
| 749 | + }); |
| 750 | + } |
| 751 | + if (line.startsWith('user')) { |
| 752 | + const v = parseTimeOutput(line); |
| 753 | + |
| 754 | + core.debug(`v: ${v}`); |
| 755 | + if (v !== undefined) |
| 756 | + results.push({ |
| 757 | + extra: name, |
| 758 | + name: 'user', |
| 759 | + value: v, |
| 760 | + unit: 's', |
| 761 | + }); |
| 762 | + } |
| 763 | + if (line.startsWith('sys')) { |
| 764 | + const v = parseTimeOutput(line); |
| 765 | + core.debug(`v: ${v}`); |
| 766 | + if (v !== undefined) |
| 767 | + results.push({ |
| 768 | + extra: name, |
| 769 | + name: 'sys', |
| 770 | + value: v, |
| 771 | + unit: 's', |
| 772 | + }); |
| 773 | + firstline = true; |
| 774 | + } |
| 775 | + core.debug('loop'); |
| 776 | + } |
| 777 | + |
| 778 | + return results; |
| 779 | +} |
| 780 | + |
693 | 781 | export async function extractResult(config: Config): Promise<Benchmark> { |
694 | 782 | const output = await fs.readFile(config.outputFilePath, 'utf8'); |
695 | 783 | const { tool, githubToken, ref } = config; |
@@ -723,6 +811,9 @@ export async function extractResult(config: Config): Promise<Benchmark> { |
723 | 811 | case 'benchmarkdotnet': |
724 | 812 | benches = extractBenchmarkDotnetResult(output); |
725 | 813 | break; |
| 814 | + case 'time': |
| 815 | + benches = extractTimeBenchmarkResult(output); |
| 816 | + break; |
726 | 817 | case 'customBiggerIsBetter': |
727 | 818 | benches = extractCustomBenchmarkResult(output); |
728 | 819 | break; |
|
0 commit comments