Does anybody know formula ?
I tried following:
1000 / ((BPM * 24) / 60).
But seems not correct.
I don't think my answer is MIDI-specific, but to convert beats-per-minute to ms-per-beat, would this work?
ms_per_beat = 1000 * 60 / bpm
In other words, I think you have an extra "24" in there.
It is simply:
Time of 1 beat in ms = 1000 * 60 / BPM = 60000 / BPM
It looks like your formula is assuming data coming from a standard midi file, where tempo is expressed in terms of ticks, where there are 24 ticks per quarter note. It's not giving you ms per beat, it's giving you ms per tick.
I wrote an article on converting BPM to MS
and I made an online app called a Delay Time Calculator that does just that including giving you dotted and triplet notes
Related
I have the following script running with the intention of closing a trade after it has been open for a period of 4 days since the trade was taken.
TimeDiff = time - time[1]
MinutesPerBar = TimeDiff / 60000
//calcuates how long one bar is in minutes
BarsSinceSwingLongCondition = barssince(SwingLongCondition)
// Calculates how many bars have passed since open of trade
CurrentSwingTradeDuration = BarsSinceSwingLongCondition * MinutesPerBar
//calculates the duration that the trade has been opened for (minutes*number of bars)
MaximumSwingTradeDuration = 4*1440
// Sets maximum trade duration. Set at 4 Days in minutes
SwingLongCloseLogic3 = CurrentSwingTradeDuration > MaximumSwingTradeDuration
// Closes trade when trade duration exceeds maximum duration set (4days)
The close logic however isn't executing when I run the strategy as i have trades open for longer than the maximum duration.
Is there any way to see what value each element of the formula is calculating so that I can see where the error is (i suspect it could be the time element). Or can anyone see where I am going wrong in the code?
The fastest way to achieve that is using the plotchar function, which would show the values in the data-window on mouse-over on each bar. The user manual contains several other techniques available for debugging.
I am trying to figure out what the value of t is ? Is it seconds or milliseconds ? The steady_clock reference does not mention the unit used.
auto t = std::chrono::steady_clock::now() / 1000;
auto p = t/1000;
I am thinking now() returns seconds and t is in milliseconds and p is in microseconds. Let me know if I am getting this right ?
It's std::chrono::time_point<std::chrono::steady_clock> (the documentation on CppReference is generally better quality).
Guessing your next question — to convert from that to seconds you would use time_since_epoch() (the documentation has an example of extracting a dimension-free number of seconds from it), or alternatively as (now - epoch) / 1_second
Unit of value returned by std::chrono::steady_clock::now() is not defined by standard (it is general value of type std::chrono::time_point).
The resolution of the std::chrono::time_point (it stores a value of type Duration indicating the time interval from the start of the Clock's epoch) is implementation dependent (platforms/compiler), and you shouldn't rely on it.
To get a desired unit, you can easily convert the time_point to a value in seconds, milliseconds, etc. by duration casting:
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
(time_since_epoch() returns a duration representing the amount of time between *this and the clock's epoch).
I need JMeter to simulate 28 days of activity (via altering time stamps) in under 1 day. There is is time function, but it doesn't look like there is one that supports anything other than current time. I also don't want to fake the dates because things like leap years and what month it is will make it incorrect.
So how can I get a time format as a delta of the current time (in milliseconds from epoch), and/or what is the best way to run a 1 day load test as if time was going 28 times faster?
UPDATE:
Thanks Dmitri T! I was able to modify your answer to what I needed (I have to restrict what hours events occur between 8am and 5pm)
For those that need it, I used the following in a JSR223 PreProcessor
timestamp=new Date();
timestamp.setDate(timestamp.getDate() - Math.floor(Math.random() * (28)));
timestamp.setHours(8,0,0,0);
timestamp.setTime(timestamp.getTime() + Math.floor(Math.random() * (1000*60*60*9)));
vars.put("TIMESTAMP", timestamp.toISOString());
You can simulate this using __time() and __longSum() functions combination like:
Now: ${__time(,)} - I guess you are already aware of it
Now + 28 days: ${__longSum(${__time(,)},2419200000,)} - where 2419200000 is
1000 * 60 * 60 * 24 * 28
^ ^ ^ ^ ^
ms sec min hour day
If Unix timestamps don't play for your for some reason you can use __javaScript() function to convert them to human-readable format like:
${__javaScript(new Date(${__longSum(${__time(,)},2419200000,)}),)}
Demo:
References:
Functions and Variables
The Function Helper Dialog
How to Use JMeter Functions
I want to test a rate-limiting app with Ruby where I define different behavior based on the number of requests per second.
For example, if I see 300 request per second or more, I want it to respond with a block.
But how would I test this by generating 300 requests per second in Ruby? I understand there are hard limitations based on CPU for example, but if I kept the number well below that limitation, how would I still send something that both exceeds the threshold and stays below?
Just looping N-times doesn't guarantee me the throughput.
The quick and dirty way is to spin up 300 threads that each do one request per second. The more elegant way is to use something like Eventmachine to create requests at the required rate. With the right non-blocking HTTP library it can easily generate that level of activity.
You also might try these tools:
ab the Apache benchmarking tool, common many systems. It's very good at abusing your system.
Seige for load testing.
How about a minimal homebrew solution:
OPS_PER_SECOND = 300
count = 0
duration = 10
start = Time.now
while true
elapsed = Time.now - start
break if elapsed >= duration
delay = (count - (elapsed / OPS_PER_SECOND)) / OPS_PER_SECOND
sleep(delay) if delay > 0
do_request
count += 1
end
I am implementing an express session with rethinkdb and I have an 'expires' field that is calculated as so: r.now() + 24 * 60 * 60 * 1000 (1 day from now).
Can I do something like this?
r.now().add(millisecondsToAdd)
There is no api documentations for this.
It will also be useful for querying.
Note: I am using the official Javascript driver.
You can do that
r.now().add(24*60 * 60 * 1000)
However, it's second, not millisecond. So to add one one more day, it is:
r.now().add(24*60*60)
When you browser the API, add saying about time: https://www.rethinkdb.com/api/ruby/add/
time.add(number[, number, ...]) → time
sub works similar to add btw.