1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//! Provides a collection of utility functions and structures primarily focused on
//! time-tracking and extracting specific data from string patterns.
//!
//! Main features:
//! - [`TickTimer`]: A utility struct that allows easy time-tracking and measures
//! elapsed time in milliseconds since the UNIX epoch.
//! It's particularly useful for performance measurement and debugging.
//! - [`extract_port_line_numbers`]: A function that extracts port and line numbers from a
//! specific string pattern (`port[number]/line[number]`).
//! It's a quick way to parse such patterns when the exact format is known in advance.
//!
//! # Examples
//!
//! Using `TickTimer` for time-tracking:
//!
//! ```
//! # use nicompiler_backend::utils::TickTimer;
//! let mut timer = TickTimer::new(); // Starts the timer
//! // ... some operations ...
//! let elapsed = timer.tick(); // Measures time since last tick.
//! println!("Elapsed time since last tick: {}ms", elapsed);
//! ```
//!
//! Extracting port and line numbers from a string:
//!
//! ```
//! # use nicompiler_backend::utils::extract_port_line_numbers;
//! let input_str = "port0/line32";
//! let (port, line) = extract_port_line_numbers(input_str);
//! assert_eq!(port, 0);
//! assert_eq!(line, 32);
//! ```
//!
//! Refer to individual function and struct documentation for detailed usage and examples.
use ;
/// A utility class for time-tracking.
///
/// `TickTimer` provides a simple way to measure elapsed time in milliseconds since the UNIX epoch
/// and the time differences between successive calls.
///
/// # Example
///
/// ```
/// # use nicompiler_backend::utils::TickTimer;
/// let mut timer = TickTimer::new(); // Starts the timer
///
/// // Some code here...
///
/// let elapsed = timer.tick(); // Returns milliseconds since last tick.
/// println!("Elapsed time since last tick: {}ms", elapsed);
///
/// // Some more code here.
///
/// timer.tick_print("Time since last tick"); // Prints the elapsed time with a message, and returns duration
/// ```
/// Extracts the port and line numbers from a given channel string.
///
/// This function assumes that the input string is of the form `port[number]/line[number]`
/// (e.g., `port0/line32`). It returns the port and line numbers as a tuple.
/// Note: The function does not perform any checks on the input format, so ensure that
/// the input string adheres to the expected format before calling this function.
///
/// # Arguments
///
/// * `chan` - A string slice representing the channel, expected to be in the format `port[number]/line[number]`.
///
/// # Returns
///
/// Returns a tuple containing the port and line numbers extracted from the input string.
///
/// # Examples
///
/// ```
/// # use nicompiler_backend::extract_port_line_numbers;
/// let input_str = "port0/line32";
/// let (port, line) = extract_port_line_numbers(input_str);
/// assert_eq!(port, 0);
/// assert_eq!(line, 32);
/// ```