How should I use locust to write stress tests for WebSocket - websocket

1.how should i keep-alive?
2.How to calculate the response time?
I rewrote loust according to online blog
class WebSocketClient(object):
def __init__(self, host):
self.host = host
self.ws = websocket.WebSocket()
def connect(self, burl, name):
start_time = time.time()
try:
self.conn = self.ws.connect(url=burl)
except websocket.WebSocketTimeoutException as e:
total_time = int((time.time() - start_time) * 1000)
events.request_failure.fire(request_type="websocket", name=name+"_error", response_time=total_time, exception=e)
flag = False
return flag
else:
total_time = int((time.time() - start_time) * 1000)
events.request_success.fire(request_type="websocket", name=name+"_right", response_time=total_time, response_length=0)
return self.conn
def recv(self):
return self.ws.recv()
def send(self, msg):
self.ws.send(msg)
def close(self):
self.ws.close()
class WebsocketLocust(Locust):
def __init__(self, *args, **kwargs):
super(WebsocketLocust, self).__init__(*args, **kwargs)
self.client = WebSocketClient(self.host)
class SearchTest(TaskSet):
#task
def searchtest(self):
self.url = 'wss://api.bbxapp.vip/v1/ifcontract/realTime'
self.client.connect(self.url, name='chat_room')
flag = True
while flag:
data ={"action":"ping"}
data =json.dumps(data)
self.client.send(data)
globals = {'true': 0}
recv = self.client.recv()
recv=json.loads(recv)
if recv["data"]== "pong":
self.client.send(data)
else:
flag = False
Output:
Name # reqs # fails Avg Min Max | Median req/s
------------------------------------------------------------------------------------
chat_room_right 1 0(0.00%) 3089 3089 3089 | 3100 0.00
------------------------------------------------------------------------------------
Total 1 0(0.00%) 0.00
the avg time is so long,I think that "total_time = int((time.time() - start_time) * 1000)" have a few mistakes.
please help me

Related

Filtering a QTableview

please have a look at the following code:
import timeit
from builtins import super
import pandas as pd
from PyQt5 import QtGui
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt, QSortFilterProxyModel
from PyQt5.QtGui import QBrush
from PyQt5.uic import loadUi
class PandasTableModel(QtGui.QStandardItemModel):
def __init__(self, data, parent=None):
QtGui.QStandardItemModel.__init__(self, parent)
self._data = data
for col in data.columns:
data_col = [QtGui.QStandardItem("{}".format(x)) for x in data[col].values]
self.appendColumn(data_col)
return
def rowCount(self, parent=None):
return len(self._data.values)
def columnCount(self, parent=None):
return self._data.columns.size
def headerData(self, x, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return self._data.columns[x]
if orientation == Qt.Vertical and role == Qt.DisplayRole:
return self._data.index[x]
def flags(self, index):
if not index.isValid():
return Qt.ItemIsEnabled
return super().flags(index) | Qt.ItemIsEditable # add editable flag.
def setData(self, index, value, role):
if role == Qt.EditRole:
# Set the value into the frame.
self._data.iloc[index.row(), index.column()] = value
return True
return False
class TableViewer(QtWidgets.QMainWindow):
def __init__(self):
super(TableViewer, self).__init__()
self.ui = loadUi("QTableViewForm.ui", self)
self.ui.cmdRun1.clicked.connect(self.RunFunction1)
self.ui.cmdRun2.clicked.connect(self.RunFunction2)
self.ui.inputFilter.textChanged.connect(self.SetFilteredView)
self.showdata()
def showdata(self):
start = timeit.default_timer()
print("Start LoadData")
data = pd.read_pickle("productdata.pkl")
self.model = PandasTableModel(data)
self.ui.tableData.setModel(self.model)
self.proxy_model = QSortFilterProxyModel()
self.proxy_model.setFilterKeyColumn(-1) # Search all columns.
self.proxy_model.setSourceModel(self.model)
self.proxy_model.sort(0, Qt.AscendingOrder)
self.proxy_model.setFilterCaseSensitivity(False)
self.ui.tableData.setModel(self.proxy_model)
print("Stop LoadData")
end = timeit.default_timer()
print("Process Time: ", (end - start))
def RunFunction1(self):
start = timeit.default_timer()
print("Start RunFunction1")
#Achtergrondkleur van de cel of rij is aanpasbaar:
item=self.model.item(2,2)
item.setBackground(QBrush(Qt.red))
print("Stop RunFunction1")
end = timeit.default_timer()
print("Process Time: ", (end - start))
def RunFunction2(self):
start = timeit.default_timer()
print("Start RunFunction1")
for i in range(10):
item = self.model.item(2, i)
item.setBackground(QBrush(Qt.green))
print("Stop RunFunction1")
end = timeit.default_timer()
print("Process Time: ", (end - start))
def SetFilteredView(self):
# print("Start set_filter")
filter_text = self.ui.inputFilter.text()
self.proxy_model.setFilterFixedString(filter_text)
filter_result = self.proxy_model.rowCount()
self.ui.lblResult.setText("(" + str(filter_result) + " records)")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
win = TableViewer()
win.show()
sys.exit(app.exec_())
I have a window with a filter input field. The filtering works great and really fast. Now i would like to be able to enter more than 1 entry to narrow the search. (Basicly an "AND" function in the filterstring).
Any suggestions how to do this ?
Cheers Johnson

why return value of a method is not accessable inside another method

class Student:
def __init__(self,student_id,marks,age):
self.__student_id=student_id
self.__marks=marks
self.__age=age
def set_student_id(self,student_id):
self.__student_id=student_id
def set_marks(self,marks):
self.__marks=marks
def set_age(self,age):
self.__age=age
def get_student_id(self):
return self.__student_id
def get_marks(self):
return self.__marks
def get_age(self):
return self.__age
def validate_age(self):
return True if self.__age>20 else False
def check_qualification(self):
a=validate_marks(self)
if a==True:
return True if self.__marks>=65 else False
else:
return False
def validate_marks(self):
return True if self.__marks in range(0,101) else False
a=Student(4,89,22)
a.check_qualification()
shows error help to fix it
I think you are facing problem where you tried to call validate_marks method.
def validate_age(self):
return self.__age > 20
def check_qualification(self):
return self.validate_marks() and self.validate_age() and self.__marks >= 65
def validate_marks(self):
return self.__marks in range(0, 101)
Usage will look like
james = Student(12, 79, 25) # 12 - Student ID, 79 Marks & 25 Age
james.check_qualification() # True or False based on validation

Use Shopify Script Editor to Set Static Price by Tag

I've examined similar questions and solutions but I was not able to get them to work with mine. I need to have a bunch of products set to a static price of $50, there is no specific discount I can apply as the actual price on these all vary. Here is the code I have so far:
class StaticPrice
def initialize(selector)
#selector = selector
end
TagSelector
class TagSelector
def initialize(tag)
#tag = tag
end
def match?(line_item)
line_item.variant.product.tags.include?(#tag)
end
end
CAMPAIGNS = [
StaticPrice.new(
TagSelector.new("boots"),
line_item.line_price == (5000), message: "SALE!")
]
Output.cart = Input.cart
**** UPDATE... Well I got it to work, however it's extremely bloated and I'm quite sure unprofessional (rookie here), but.. it works.. This allows me to set static prices on products based off tags for a particular sale while at the same time not allowing someone to use a coupon to get any additional price off of the sale item.. I appreciate any suggestions for improvement ****
case Input.cart.discount_code
when CartDiscount::Percentage
if Line_items.quantity > 1
Input.cart.discount_code.reject(message: "Coupons can not be combined with BOGO promotion")
end
end
class ItemCampaign
def initialize(selector, discount, partitioner)
#selector = selector
#discount = discount
#partitioner = partitioner
end
def run(cart)
applicable_items = cart.line_items.select do |line_item|
#selector.match?(line_item)
end
discounted_items = #partitioner.partition(cart, applicable_items)
discounted_items.each do |line_item|
#discount.apply(line_item)
end
end
end
class TagSelector
def initialize(tag)
#tag = tag
end
def match?(line_item)
line_item.variant.product.tags.include?(#tag)
end
end
class PercentageDiscount50
def initialize(percent, message)
#percent = Money.new(cents: 100) * 50
#message = message
end
def apply(line_item)
line_discount = line_item.line_price - line_item.line_price + Money.new(cents: 100) * 50
new_line_price = Money.new(cents: 100) * 50
line_item.change_line_price(new_line_price, message: #message)
puts "Discounted line item with variant #{line_item.variant.id} by #{line_discount}."
end
end
class PercentageDiscount40
def initialize(percent, message)
#percent = Money.new(cents: 100) * 40
#message = message
end
def apply(line_item)
line_discount = line_item.line_price - line_item.line_price + Money.new(cents: 100) * 40
new_line_price = Money.new(cents: 100) * 40
line_item.change_line_price(new_line_price, message: #message)
puts "Discounted line item with variant #{line_item.variant.id} by #{line_discount}."
end
end
class PercentageDiscount30
def initialize(percent, message)
#percent = Money.new(cents: 100) * 30
#message = message
end
def apply(line_item)
line_discount = line_item.line_price - line_item.line_price + Money.new(cents: 100) * 30
new_line_price = Money.new(cents: 100) * 30
line_item.change_line_price(new_line_price, message: #message)
puts "Discounted line item with variant #{line_item.variant.id} by #{line_discount}."
end
end
class PercentageDiscount20
def initialize(percent, message)
#percent = Money.new(cents: 100) * 20
#message = message
end
def apply(line_item)
line_discount = line_item.line_price - line_item.line_price + Money.new(cents: 100) * 20
new_line_price = Money.new(cents: 100) * 20
line_item.change_line_price(new_line_price, message: #message)
puts "Discounted line item with variant #{line_item.variant.id} by #{line_discount}."
end
end
class PercentageDiscount10
def initialize(percent, message)
#percent = Money.new(cents: 100) * 10
#message = message
end
def apply(line_item)
line_discount = line_item.line_price - line_item.line_price + Money.new(cents: 100) * 10
new_line_price = Money.new(cents: 100) * 10
line_item.change_line_price(new_line_price, message: #message)
puts "Discounted line item with variant #{line_item.variant.id} by #{line_discount}."
end
end
class LowToHighPartitioner
def initialize(paid_item_count, discounted_item_count)
#paid_item_count = paid_item_count
#discounted_item_count = discounted_item_count
end
def partition(cart, applicable_line_items)
sorted_items = applicable_line_items.sort_by{|line_item| line_item.variant.price}
total_applicable_quantity = sorted_items.map(&:quantity).reduce(0, :+)
discounted_items_remaining = Integer(total_applicable_quantity / (#paid_item_count + #discounted_item_count) * #discounted_item_count)
discounted_items = []
sorted_items.each do |line_item|
break if discounted_items_remaining == 0
discounted_item = line_item
if line_item.quantity > discounted_items_remaining
discounted_item = line_item.split(take: discounted_items_remaining)
position = cart.line_items.find_index(line_item)
cart.line_items.insert(position + 0, discounted_item)
end
discounted_items_remaining -= discounted_item.quantity
discounted_items.push(discounted_item)
end
discounted_items
end
end
CAMPAIGNS = [
ItemCampaign.new(
TagSelector.new("SCRIPT50"),
PercentageDiscount50.new(10, "$50 FINAL SALE!"),
LowToHighPartitioner.new(0,1),
),
ItemCampaign.new(
TagSelector.new("SCRIPT40"),
PercentageDiscount40.new(10, "$40 FINAL SALE!"),
LowToHighPartitioner.new(0,1),
),
ItemCampaign.new(
TagSelector.new("SCRIPT30"),
PercentageDiscount30.new(10, "$30 FINAL SALE!"),
LowToHighPartitioner.new(0,1),
),
ItemCampaign.new(
TagSelector.new("SCRIPT20"),
PercentageDiscount20.new(10, "$20 FINAL SALE!"),
LowToHighPartitioner.new(0,1),
),
ItemCampaign.new(
TagSelector.new("SCRIPT10"),
PercentageDiscount10.new(10, "$10 FINAL SALE!"),
LowToHighPartitioner.new(0,1),
)
]
CAMPAIGNS.each do |campaign|
campaign.run(Input.cart)
end
Output.cart = Input.cart
When you are instantiating a new StaticPrice object, you are sending in 3 attributes but your object accepts only the one. You instantiate TagSelector, but you never use the match? method.
Without knowing more, seeing more, and having more of your explanations, the amount of code you are providing is of little use.
Why not just iterate the cart, and set prices. That is trivial and does not involve complex objects. Experiment with simpler code, and build up to a more organized approach as you gain confidence. There is little need for the campaign, StaticPrice and TagSelector till you actually have some working script code that exhibits a need for them.

Snakes and Ladders using tkinter python

import random
from tkinter import *
class Spinner(object):
#staticmethod
def getSpin():
newSpin = random.randint(1,6)
return newSpin
class Player(object):
def __init__(self,name):
self.position = 1
self.name = name
def setName(self,name):
self.name = name
def changePosition(self,number):
self.position = self.position + number
def setPosition(self,pos):
self.position = pos
return self.position
def getPosition(self):
return self.position
def getName(self):
return self.name
def spin(self):
newSpin = Spinner.getSpin()
self.position = self.position + newSpin
print(str(self.name) + "'s spin was: " + str(newSpin))
class Path(object):
#staticmethod
def buildLadders():
ladders = [[0 for x in range(2)] for x in range(9)]
ladders[0][0] = 2
ladders[0][1] = 9
ladders[1][0] = 8
ladders[1][1] = 11
return ladders
#staticmethod
def buildChutes():
chutes = [[0 for x in range(2)] for x in range(10)]
chutes[0][0] = 9
chutes[0][1] = 3
chutes[1][0] = 12
chutes[1][1] = 6
return chutes
class Check(Player):
def __init__(self):
super(Check,self).__init__()
def checkLadders(self):
ladders = Path.buildLadders()
for i in range(0,len(ladders),1):
if self.getPosition() == ladders[i][0]:
self.position = self.setPosition(ladders[i][1])
print(str(self.name) + " Landed on a Ladder! from " + \
str(ladders[i][0]) +" to " + str(ladders[i][1]))
def newPosition(self):
return self.position
def checkChutes(self):
chutes = Path.buildChutes()
for i in range(0,len(chutes),1):
if self.getPosition() == chutes[i][0]:
self.position = self.setPosition(chutes[i][1])
print(str(self.name) + " Landed on a Chutes!")
class Match_Position(Player):
def __init__(self,name):
super(Match_Position,self).__init__(name)
self.match = [[70,235],
[180,235],
[290,235],
[400, 235],
[400, 140],
[290, 140],
[180, 140],
[70, 140],
[70, 45],
[180, 45],
[290, 45],
[400, 45]]
self.name = name
self.players = Player(self.name)
self.pos = self.players.getPosition()
self.position_actual = []
self.__str__()
self.actualpos()
def __str__(self):
for j in range(len(self.match)):
if self.pos == (j+1):
self.position_actual.append(self.match[j][0])
self.position_actual.append(self.match[j][1])
def actualpos(self):
return self.position_actual
class Display(object):
def __init__(self,master,img,name):
canvas_width = 650
canvas_height = 300
self.name = name
print(self.name)
self.pos = Match_Position(self.name).actualpos()
print(self.pos)
self.canvas = Canvas(master, width = canvas_width, height = canvas_height, bg = "yellow")
self.canvas.grid(padx=0, pady=0)
self.canvas.create_image(300,150,anchor=CENTER, image = img)
self.animate(master)
def animate(self,master):
Button(master, text= "ROLL", command=self.say_hello(self.name[0])).grid( row=3, column=0, sticky=E)
Button(master, text= "ROLL", command=self.say_hello1(self.name[1])).grid( row=3, column=1, sticky=E)
def say_hello(self,name):
self.name = name
self.name = Player(self.name)
self.name.spin()
Check.checkLadders(self.name)
Check.checkChutes(self.name)
x = self.pos[0]
y = self.pos[1]
self.canvas.create_oval(x,y,x+20,y+20, fill='blue')
def say_hello1(self,name):
self.name = name
self.name = Player(self.name)
self.name.spin()
Check.checkLadders(self.name)
Check.checkChutes(self.name)
x = self.pos[0]
y = self.pos[1]
self.canvas.create_oval(x,y,x+20,y+20, fill='red')
class BounceController(object):
def __init__(self):
master = Tk()
master.title("Snake and Ladder")
master.geometry("700x350")
img = PhotoImage( file = "puzzlor-chutes-and-ladders.gif" )
name = ['n','s']
Display(master,img,name).animate(master)
master.mainloop()
def main():
BounceController()
main()
It printed out this, but the error:
"'Player' object does not support indexing" pop out.
What is object does not support indexing error is?
And when I click the button, the oval does not actually move.
And using tkinter Button, I can call the method, right?
But by doing so, if I want to make for example, clicking the button, result to the oval moving to different location, how do I achieve that? Since as my code, above, the oval does not move eventhough the button is clicked.
Thanks. Since I'm quite new to python and programming, any help would be such a gratitude.
Indexing is when you suffix an object with [n], where n is an int. Here is how to reproduce the message.
>>> class C: pass
>>> C()[1]
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
C()[1]
TypeError: 'C' object does not support indexing
The File entry above the error message tells you the line number and expression that gave the error. Someplace in your code, as indicated by the traceback you did not show us, you have x[n], where x in an instance of the Player class you defined.
An object is subscriptable if and only if it has a __getitem__ method, which Player does not have and should not have.

How to get a stopwatch program running?

I borrowed some code from a site, but I don't know how to get it to display.
class Stopwatch
def start
#accumulated = 0 unless #accumulated
#elapsed = 0
#start = Time.now
#mybutton.configure('text' => 'Stop')
#mybutton.command { stop }
#timer.start
end
def stop
#mybutton.configure('text' => 'Start')
#mybutton.command { start }
#timer.stop
#accumulated += #elapsed
end
def reset
stop
#accumulated, #elapsed = 0, 0
#mylabel.configure('text' => '00:00:00.00.000')
end
def tick
#elapsed = Time.now - #start
time = #accumulated + #elapsed
h = sprintf('%02i', (time.to_i / 3600))
m = sprintf('%02i', ((time.to_i % 3600) / 60))
s = sprintf('%02i', (time.to_i % 60))
mt = sprintf('%02i', ((time - time.to_i)*100).to_i)
ms = sprintf('%04i', ((time - time.to_i)*10000).to_i)
ms[0..0]=''
newtime = "#{h}:#{m}:#{s}.#{mt}.#{ms}"
#mylabel.configure('text' => newtime)
end
end
How would I go about getting this running?
Thanks
Based upon the additional code rkneufeld posted, this class requires a timer that is specific to Tk. To do it on the console, you could just create a loop that calls tick over and over. Of course, you have to remove all the code that was related to the GUI:
class Stopwatch
def start
#accumulated = 0 unless #accumulated
#elapsed = 0
#start = Time.now
# #mybutton.configure('text' => 'Stop')
# #mybutton.command { stop }
# #timer.start
end
def stop
# #mybutton.configure('text' => 'Start')
# #mybutton.command { start }
# #timer.stop
#accumulated += #elapsed
end
def reset
stop
#accumulated, #elapsed = 0, 0
# #mylabel.configure('text' => '00:00:00.00.000')
end
def tick
#elapsed = Time.now - #start
time = #accumulated + #elapsed
h = sprintf('%02i', (time.to_i / 3600))
m = sprintf('%02i', ((time.to_i % 3600) / 60))
s = sprintf('%02i', (time.to_i % 60))
mt = sprintf('%02i', ((time - time.to_i)*100).to_i)
ms = sprintf('%04i', ((time - time.to_i)*10000).to_i)
ms[0..0]=''
newtime = "#{h}:#{m}:#{s}.#{mt}.#{ms}"
# #mylabel.configure('text' => newtime)
end
end
watch = Stopwatch.new
watch.start
1000000.times do
puts watch.tick
end
You'll end up with output like this:
00:00:00.00.000
00:00:00.00.000
00:00:00.00.000
...
00:00:00.00.000
00:00:00.00.000
00:00:00.01.160
00:00:00.01.160
...
Not particularly useful, but there it is. Now, if you're looking to do something similar in Shoes, try this tutorial that is very similar.
I believe you have found the example on this site
I'm repeating what is already on the site but you are missing:
require 'tk'
as well as initialization code:
def initialize
root = TkRoot.new { title 'Tk Stopwatch' }
menu_spec = [
[
['Program'],
['Start', lambda { start } ],
['Stop', lambda { stop } ],
['Exit', lambda { exit } ]
],
[
['Reset'], ['Reset Stopwatch', lambda { reset } ]
]
]
#menubar = TkMenubar.new(root, menu_spec, 'tearoff' => false)
#menubar.pack('fill'=>'x', 'side'=>'top')
#myfont = TkFont.new('size' => 16, 'weight' => 'bold')
#mylabel = TkLabel.new(root)
#mylabel.configure('text' => '00:00:00.0', 'font' => #myfont)
#mylabel.pack('padx' => 10, 'pady' => 10)
#mybutton = TkButton.new(root)
#mybutton.configure('text' => 'Start')
#mybutton.command { start }
#mybutton.pack('side'=>'left', 'fill' => 'both')
#timer = TkAfter.new(1, -1, proc { tick })
Tk.mainloop
end
end
Stopwatch.new
I would suggest reading through the rest of the site to understand what is all going on.
I was searching for a quick and dirty stop watch class to avoid coding such and came upon the site where the original code was posted and this site as well.
In the end, I modified the code until it met what I think that I was originally searching for.
In case anyone is interested, the version that I have ended up thus far with is as follows (albeit that I have yet to apply it in the application that I am currently updating and for which I want to make use of such functionality).
# REFERENCES
# 1. http://stackoverflow.com/questions/858970/how-to-get-a-stopwatch-program-running
# 2. http://codeidol.com/other/rubyckbk/User-Interface/Creating-a-GUI-Application-with-Tk/
# 3. http://books.google.com.au/books?id=bJkznhZBG6gC&pg=PA806&lpg=PA806&dq=ruby+stopwatch+class&source=bl&ots=AlH2e7oWWJ&sig=KLFR-qvNfBfD8WMrUEbVqMbN_4o&hl=en&ei=WRjOTbbNNo2-uwOkiZGwCg&sa=X&oi=book_result&ct=result&resnum=8&ved=0CEsQ6AEwBw#v=onepage&q=ruby%20stopwatch%20class&f=false
# 4. http://4loc.wordpress.com/2008/09/24/formatting-dates-and-floats-in-ruby/
module Utilities
class StopWatch
def new()
#watch_start_time = nil #Time (in seconds) when the stop watch was started (i.e. the start() method was called).
#lap_start_time = nil #Time (in seconds) when the current lap started.
end #def new
def start()
myCurrentTime = Time.now() #Current time in (fractional) seconds since the Epoch (January 1, 1970 00:00 UTC)
if (!running?) then
#watch_start_time = myCurrentTime
#lap_start_time = #watch_start_time
end #if
myCurrentTime - #watch_start_time;
end #def start
def lap_time_seconds()
myCurrentTime = Time.now()
myLapTimeSeconds = myCurrentTime - #lap_start_time
#lap_start_time = myCurrentTime
myLapTimeSeconds
end #def lap_time_seconds
def stop()
myTotalSecondsElapsed = Time.now() - #watch_start_time
#watch_start_time = nil
myTotalSecondsElapsed
end #def stop
def running?()
!#watch_start_time.nil?
end #def
end #class StopWatch
end #module Utilities
def kill_time(aRepeatCount)
aRepeatCount.times do
#just killing time
end #do
end #def kill_time
elapsed_time_format_string = '%.3f'
myStopWatch = Utilities::StopWatch.new()
puts 'total time elapsed: ' + elapsed_time_format_string % myStopWatch.start() + ' seconds'
kill_time(10000000)
puts 'lap time: ' + elapsed_time_format_string % myStopWatch.lap_time_seconds() + ' seconds'
kill_time(20000000)
puts 'lap time: ' + elapsed_time_format_string % myStopWatch.lap_time_seconds() + ' seconds'
kill_time(30000000)
puts 'lap time: ' + elapsed_time_format_string % myStopWatch.lap_time_seconds() + ' seconds'
puts 'total time elapsed: ' + elapsed_time_format_string % myStopWatch.stop() + ' seconds'
Simple stopwatch script:
# pass the number of seconds as the parameter
seconds = eval(ARGV[0]).to_i
start_time = Time.now
loop do
elapsed = Time.now - start_time
print "\e[D" * 17
print "\033[K"
if elapsed > seconds
puts "Time's up!"
exit
end
print Time.at(seconds - elapsed).utc.strftime('%H:%M:%S.%3N')
sleep(0.05)
end
Run like this in your terminal (to mark a lap, just tap enter):
# 10 is the number of seconds
ruby script.rb 10
# you can even do this:
ruby script.rb "20*60" # 20 minutes

Resources