[Powershell] 프로그램 실행시간 측정
몰랐는데 은근 유용한게 많다
Published
![[Powershell] 프로그램 실행시간 측정](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Funsplash%2FmBQIfKlvowM%2Fupload%2Fv1652767294871%2FR68lgreZI.jpeg&w=3840&q=75)
보통은 스크립트를 만들어서 끝난 시점의 시간에서 시작한 시점의 시간을 빼서 실행 시간을 측정한다. 물론 Powershell에서도 그런 방법이 있겠지만 훨씬 간편한 방법이 있다.
바로 Measure-Command 이다
Measure-Command 사용법
Mesure-Command { ls }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 1
Ticks : 12375
TotalDays : 1.43229166666667E-08
TotalHours : 3.4375E-07
TotalMinutes : 2.0625E-05
TotalSeconds : 0.0012375
TotalMilliseconds : 1.2375
사용법은 정말 간단하다. 그냥 명령어 뒤 중괄호 안에 프로그램을 넣고 실행시키면 알아서 실행하고 시간까지 측정해준다. 만약 여러개의 명령어를 실행하고 싶다면 ;로 구분하면 된다.
출력을 볼 수 없다?
위에서 볼 수 있듯이 stdout으로 나와야할 결과들이 출력되지 않는다. 만약 결과를 보고 싶다면 Out-Default를 pipe 하면 된다.
Measure-Command {ls | Out-Default}
d---- 2021-12-03 오후 2:49 1 blog
d---- 2022-03-23 오후 10:14 1 go
d---- 2022-05-13 오후 4:50 1 golang
d---- 2022-05-09 오전 11:33 1 java
d---- 2022-04-23 오후 3:12 1 js
d---- 2022-04-12 오후 4:54 1 localstack
d---- 2022-03-29 오전 12:31 1 project
d---- 2022-05-10 오후 1:49 1 python
d---- 2022-01-11 오후 12:40 1 SDK
d---- 2021-05-05 오전 2:43 1 TEMP
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 21
Ticks : 214767
TotalDays : 2.48572916666667E-07
TotalHours : 5.96575E-06
TotalMinutes : 0.000357945
TotalSeconds : 0.0214767
TotalMilliseconds : 21.4767
원하는 시간만 따로 빼기
11개의 값 중에서 원하는 값이 있다면 그 값만 불러올 수도 있다.
(Measure-Command {ls}).TotalSeconds
0.0008601
전체를 괄호로 감싼 뒤 .원하는 값을 통해서 편리하게 가져올 수 있다.
1.4K views


![[YSM의 서버 세팅] - Ssl 갱신 자동화](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FYFFGkE3y4F8%2Fupload%2F403911f5e0e7609f6c6b0addeb5fef78.jpeg&w=3840&q=75)
![[YSM의 서버 세팅] - Oracle Cloud ARM](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2Fv7daTKlZzaw%2Fupload%2F7d95d24381c2f051a55e244bf2da9992.jpeg&w=3840&q=75)
![[image-optimize] 2. 이미지는 어떻게 최적화 해야할까?](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FHkM6gUe6CiU%2Fupload%2F37da18c9528d9b74d7fbf93ef94d4853.jpeg&w=3840&q=75)