-
Notifications
You must be signed in to change notification settings - Fork 1
Собственная реализация хронометра #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,5 @@ | ||||||||||||||||||||||||
| using System; | ||||||||||||||||||||||||
| using System.IO; | ||||||||||||||||||||||||
| using System.Reflection; | ||||||||||||||||||||||||
| using System.Diagnostics; | ||||||||||||||||||||||||
| using System.Runtime.CompilerServices; | ||||||||||||||||||||||||
| using ScriptEngine.Machine.Contexts; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #if NET6_0_OR_GREATER | ||||||||||||||||||||||||
|
|
@@ -12,11 +11,15 @@ namespace OscriptChronometer | |||||||||||||||||||||||
| [ContextClass("Хронометр", "Chronometer")] | ||||||||||||||||||||||||
| public class Chronometer : AutoContext<Chronometer> | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| private static readonly long Frequency = Stopwatch.Frequency; | ||||||||||||||||||||||||
| private static readonly double TicksToNs = 1_000_000_000.0 / Frequency; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [ContextProperty("Наносекунд", "Nanoseconds")] | ||||||||||||||||||||||||
| public decimal Nanoseconds { get; private set; } | ||||||||||||||||||||||||
| public decimal Nanoseconds => (decimal) (_elapsedTicks * TicksToNs); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private Perfolizer.Horology.StartedClock _Clock; | ||||||||||||||||||||||||
| private long _startTick; | ||||||||||||||||||||||||
| private long _elapsedTicks; | ||||||||||||||||||||||||
| private bool _isRunning; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [ScriptConstructor] | ||||||||||||||||||||||||
| public static Chronometer Constructor() | ||||||||||||||||||||||||
|
|
@@ -25,16 +28,28 @@ public static Chronometer Constructor() | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [ContextMethod("Старт", "Start")] | ||||||||||||||||||||||||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||||||||||||||||||||||||
| public void Start() | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| _Clock = Perfolizer.Horology.Chronometer.Start(); | ||||||||||||||||||||||||
| if (!_isRunning) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| _startTick = GetTick(); | ||||||||||||||||||||||||
| _isRunning = true; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+34
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After a Proposed fix if (!_isRunning)
- {
+ {
+ _elapsedTicks = 0;
_startTick = GetTick();
_isRunning = true;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [ContextMethod("Стоп", "Stop")] | ||||||||||||||||||||||||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||||||||||||||||||||||||
| public void Stop() | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| var clockElapsed = _Clock.GetElapsed(); | ||||||||||||||||||||||||
| Nanoseconds = (decimal) clockElapsed.GetNanoseconds(); | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| if (_isRunning) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| _elapsedTicks = GetTick() - _startTick; | ||||||||||||||||||||||||
| _isRunning = false; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||||||||||||||||||||||||
| private static long GetTick() => Stopwatch.GetTimestamp(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in user-facing error message: "Отсутсвует" → "Отсутствует"
"Отсутсвует" is missing the letter 'т' — the correct spelling is "Отсутствует".
📝 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents