Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

run benchmark at cursor (#972) #1303

Merged
merged 6 commits into from
Nov 9, 2017
Merged

run benchmark at cursor (#972) #1303

merged 6 commits into from
Nov 9, 2017

Conversation

buyology
Copy link
Contributor

this is a stab at #972 along the lines of the discussion to have run benchmark available at the cursor level

note:

  • runs with the -benchmem flag by default
  • use -run=^$ to exclude all tests from being run

look and feel

run-benchmark

(nb: this is my first foray into typescript, and my first locs in javascript in many years so please bear with me)

cc @scriptnull @ironcladlou @campoy @rakyll

@msftclas
Copy link

msftclas commented Oct 25, 2017

CLA assistant check
All CLA requirements met.

Copy link
Contributor

@ramya-rao-a ramya-rao-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@buyology Thanks for your patience, it took me a while to get to the PRs this last month.

Good start, I have left a few comments, mainly around refactoring some code. Please do take a look

src/testUtils.ts Outdated
* Get the test target arguments.
*
* @param testconfig Configuration for the Go extension.
*/
function targetArgs(testconfig: TestConfig): Thenable<Array<string>> {
function testTargetArgs(testconfig: TestConfig): Thenable<Array<string>> {
if (testconfig.functions) {
return Promise.resolve(['-run', util.format('^%s$', testconfig.functions.join('|'))]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a separate benchmarkTargetArgs, you can just use -bench here instead of -run if testconfig.isBenchmark is true

src/testUtils.ts Outdated
* Returns whether a given function name has a test prefix.
* Test functions have "Test" or "Example" as a prefix.
*
* @param the function name.
* @return whether the name has a test function prefix.
*/
function hasTestFunctionPrefix(name: string): boolean {
export function hasTestFunctionPrefix(name: string): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no real point of making this a separate function in the first place (my apologies).

Instead of exporting this prefix function and adding another for benchmark, we can simplify things as below

  • remove hasTestFunctionPrefix and move the prefix check into getTestFunctions
  • create and export a new function getBenchmarkFunctions which will have the same code as getTestFunctions but with a different prefix check.

It will definitely get simpler when importing these functions in other files


});

return Promise.resolve(codelens);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Promise should resolve only after both tests and benchmark functions are found

@ramya-rao-a ramya-rao-a merged commit abcd89a into microsoft:master Nov 9, 2017
@ramya-rao-a
Copy link
Contributor

@buyology I went ahead and made the refactorings myself, hope you dont mind.
Great work!

@buyology
Copy link
Contributor Author

buyology commented Nov 9, 2017

@ramya-rao-a did not mind :) thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants