Increase value over time using a mathematical algorithm

I am writing a test tool that puts a lot of stress on a network service. I would like this tool to start with a small load and gradually increase over time. I'm sure there is some kind of trigonometry that can do similar calculations in one line of code, but I'm not a mathematical guru (yet). Is there some kind of library (or a simple algorithm) that can help with this calculation?

Ideally, the code should take several arguments:

  • to use (determine how quickly the value increases
  • initial value
  • final value (maximum)
  • time (the amount of time between the start and end value)
  • step (grain in milliseconds)

Thus, each [step] event will be raised, indicating what value is at a given time.

This is an ideal implementation, so I am open to suggestions.

Any input would be appreciated, thanks :)

EDIT:

Let me be clearer ... the amount that increases the value is not linear, it is a curve.

+3
source share
8 answers

If you want some form of saturation (see the sigmoid function ), see my answer here . Another common form of function is linear or exponential growth . Just let me know if you need one of them.

+3
source

I think you need a facilitating function.

, . : Tweener -, .

-.

+2

value = (endValue - StartValue)/(time/stepSize) * currentStep;

+1

heck ,

0

, ( "", ): - .

, , ( ).

, "" , . , , last-value + (milliseconds-since-last_step * -).

. , ( ), , .

0

- ? ( python, , # )

, f, 0 1:

def my_stepper(f, start, end, time, step_size, current_step):
   x = current_step * step_size / time 
   f_1 = f(1)
   f_0 = f(0)
   y = start + (end - start) * (f(x)- f_0) / (f_1 - f_0)
   return y

for i in xrange(11):
   # increment increases over time
   print 'exp', my_stepper(math.exp, 100., 200., 10., 1., i)
   # increment decreases over time
   print 'log', my_stepper(lambda x: math.log(1+x), 100., 200., 10., 1., i)
0

Pseduo :

F (a + b * x) x, , 0, - InverseF - F.

x = 0, F (a) = start a = InverseF () , b = (InverseF (end) -a)/time, b = (inverseF (end) -nverseF (start))/time

x = step,

- F (a + b *), ,

F (inverseF (start) + (inverseF (end) -nverseF ())/ * )

- .

,

F (x) , .. f (x) = x

value = start + (end-start)/time * step

F (x) - x * x,

value = (sqrt (start) + (sqrt (end) -sqrt (start))/time * step) * (sqrt (start) + (sqrt (end) -sqrt (start))/time * step)

F (x) - exp (x),

value = Exp (log (start) + (log (end) -log (start))/time * step)

F (x) - log (x),

value = Log ((exp (start) + (exp (end) -exp (start))/time * step)

..

.

a + b * F (x) x, , 0, -

a + b * F (0) = start a + b * F (time) = end a b,

value = start + (end-start)/(F () -F (0)) * (F (x) -F (0))

x,

value = start + (end-start)/(F () -F (0)) * (F () -F (0))

, .

0

. , , , , , . , .

, :

Spread(startingValue, endingValue, time/step, x => 1-(1-x)*(1-x))

:

FocusOnHighLoad   = x => 1-(1-x)*(1-x)
FocusOnLowLoad    = x => x * x
FocusOnMediumLoad = x => (1 + Math.Pow(x * 2 - 1, 3)) / 2

:

foreach (double load in Spread(50, 1000, 9, FocusOnHighLoad))
    Console.WriteLine("Working with {0} load", load);

Working with 50 load
Working with 272.65625 load
Working with 465.625 load
Working with 628.90625 load
Working with 762.5 load
Working with 866.40625 load
Working with 940.625 load
Working with 985.15625 load
Working with 1000 load
0
source

Source: https://habr.com/ru/post/1718343/


All Articles