A what-if analyzer for code
Here's something cool I'd like to have:
A live what-if functionality for testing code.
Right now I'm trying to do some simple math, like this:
int updatesPerSec = 3000;
long batchesPerSec = updatesPerSec / MAX_UPDATES_PER_BATCH;
long periodPerBatch = 1000 / batchesPerSec;
int updatesPerBatch = (int) (updatesPerSec / batchesPerSec);
And I'm going like this in my head...
MAX_UPDATES is 100 so updatesPerSec divided by 100 is 30 so batchesPerSec is
30.
1000 milliseconds in a second divided by batchesPerSec, which is 30, equals,
eh,
30-something. 30-something divided by batchesPerSec which was, hm, 3000
divided
by 100 equals 30, is 1. 1? One update per batch, thirty batches per second
is not even
close to 3000 updates per second. Oh, it's updatesPerSec, which is 3000,
divided by
batchesPerSec, which was... Argh.
Still with me?
What I'd like to do is just select the code and start the what-if-analyzer.
The analyzer
executes the code and presents the values in a table, like this:
updatesPerSec 3000
batchesPerSec 30
periodPerBatch 33.33...
updatesPerBatch 90
Wonderful. I can check in an instant that my math seems reasonable. But what
if
updatesPerSec is 10? Simple, just click 'Add column' and fill in the value.
Like this:
updatesPerSec 3000 10
batchesPerSec 30 0
periodPerBatch 33.33... 0-division
updatesPerBatch 90 0-division
Oh dear, there's something wrong with the values. We need a lower bound on
batchesPerSec. I'll edit...
int updatesPerSec = 3000;
long batchesPerSec = Math.max(updatesPerSec / MAX_UPDATES_PER_BATCH, 1);
long periodPerBatch = 1000 / batchesPerSec;
int updatesPerBatch = (int) (updatesPerSec / batchesPerSec);
Let's look at the analysis again.
updatesPerSec 3000 10
batchesPerSec 30 1
periodPerBatch 33.33... 1000
updatesPerBatch 90 10
Perfect. Now what about larger numbers...
Can I have this? Pretty please with a donut on top?
/Mikael
Please sign in to leave a comment.
In the debugger (Alt-F8) switch to Code Fragment Mode,
paste your code fragment, press Evaluate.
--
regards,
--
Alexey Kudravtsev
Software Developer
JetBrains, Inc, http://www.jetbrains.com
"Develop with pleasure!"
"Mikael Karlsson" <mikael.karlsson@pitch.se> wrote in message
news:ev2obn$h44$1@is.intellij.net...
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>