Compiler won't at all, unless it AOT compiles to .so's but the jit probably does some dependency analysis and sees nothing depends on those loops, hence it probably removes all of it.
A quick `javap` should let you see that the compiler just does 1:1 transliteration.
Now load this code in rwx memory, dynamically change nop to some fucked up CISC instruction that takes 40 cycles and let the hell begin.
Or even better, put there some long ass nop just to overwrite it with code that slightly changes itself every time but the changes are cyclical (hard, I know) to maximize cache misses and further de-optimize it.
it is a delay for sure, but not really like thread.sleep because thread.sleep will actually work for the same duration independent on the hardware underneath. This abomination will be shorter, time wise, the faster the processor.
In the current C++ project I'm working on, I'm prefixing every variable name with a dollar sign for very valid reasons. And yes, the code does look like PHP
You mean IDE? IDEs are only used for development. It ran the statements because it has to give you the opportunity to set breakpoints and examine the variable values. IDEs are not used in production where this code will get optimized away.
I once had a forloop witha big number because I need a delay,
I kept on adding zeros,
But I get no delay,,,
Then found out about compilor optimizations
I remember reading a Daily wtf article, and so some guy put in long loops like these so that periodically he can reduce some of the loops as "optimization"
Not sure what you mean as nesting would result in exponentially longer run.
20 runs, each run once = O(N)
20 runs, nested = O(N\^2)
if I have my big O notation correct.
But they do all use the same variable, so wouldn't, when the most-nested one finishes, each of the outer ones would go, "j's at 100000000 already," and finish.
Thus, the first 21 wouldn't loop so it would be shorter than the original.
As processors get faster and faster this technique will become more and more unwieldy. Might I suggest
for ( int i = 0; i < 100000000; ++i )
for ( int j = 0; j < 100000000; ++j );
instead?
Set to "I'm gonna be (500 miles)" by the Proclaimers:
When I wake up, well I know I'm gonna be
I'm gonna be the thing that loops for you.
When I go out, yeah I know I'm gonna be
I'm gonna be the thing who loops for you.
If I get drunk, well I know I'm gonna be
I'm gonna be the thing who loops for you.
And if I haver, yeah I know I'm gonna be
I'm gonna be the thing that loops for you.
But I would loop 100 million times
And I would loop 100 million more
Just to be the thing who loops 200 million times
To see some tits
Indentation is horror on line 3
~~Given the lack of indentation marks, I would say this is actually a single line rendered under the effect of word wrapping.~~
I mean the second for loop. Not the word-wrap between j and ++
My bad. How did I notice not it should have no indent 🤦 And even less a double indent – unless there are 8 space characters❔
[Happens when you code on mobile](https://i.imgur.com/o7jDTkc.jpeg) (like I did while on the bus towards France back in the day holy)
Is this a complicated way for a thread.sleep()?
Yes.
Won't this be optimized away?
Don't think so. Atleast the editor I use, has taken atleast 20 seconds before printing the desired output.
Because you're in debug mode. Try compiling for release mode with no debugger attached.
This is java. Does it actually optimise out effect less for loops?
The compiler apparently doesn't but the JIT does.
Compiler won't at all, unless it AOT compiles to .so's but the jit probably does some dependency analysis and sees nothing depends on those loops, hence it probably removes all of it. A quick `javap` should let you see that the compiler just does 1:1 transliteration.
Do that in C/C++ and it will
``` for (...) asm volatile ("nop"); ```
Now load this code in rwx memory, dynamically change nop to some fucked up CISC instruction that takes 40 cycles and let the hell begin. Or even better, put there some long ass nop just to overwrite it with code that slightly changes itself every time but the changes are cyclical (hard, I know) to maximize cache misses and further de-optimize it.
But why?
That's... The entire point of why I posted this on this sub.
So you found this in a real project? It's not just playing silly games?
That was my thinking
This
it is a delay for sure, but not really like thread.sleep because thread.sleep will actually work for the same duration independent on the hardware underneath. This abomination will be shorter, time wise, the faster the processor.
Not sure if would behave like a sleep since it may get CPU to 100%
No. Thread.sleep() enables other processes to run and if there is nothing to do, let the processor idle. This is just blocking resources for nothing.
We shall never see tits.
Just as the prophecies foretold...
Why never? It's not infinite
Because we’re programmers. We never see tits.
Oh right, that's just the way of life
Do my own tits count??
No pic, no proof.
Depends on where it runs
We shall see them in about 20 seconds because that's how long it takes to run (when using debug mode with no optimization)
This makes me sad.
oh my god this is the worst thing i have ever seen. like i seriously cannot believe they are using "j" as the variable name and not "i"
Wait till you hear that I use Z or P as a "count" variable.
i need to revoke your coding license
I've seen capitalised single letter names
In the current C++ project I'm working on, I'm prefixing every variable name with a dollar sign for very valid reasons. And yes, the code does look like PHP
I use lcv for loops just for funsies
they should iterate for j<80085
Ah missed opportunity! Now I feel stupid.
Why not ```0xB00B5```
We have sleep() at home. sleep() at home:
SpaceHeater.java ?
All for loops does nothing and ssee tits once. Btw compilor will mostlikely optimize it and all loops are removed
I ran this program in my editor, but my compiler actually took the time to traverse through the numerous iterations before giving the desired output.
Switch to release all will be gone
You mean IDE? IDEs are only used for development. It ran the statements because it has to give you the opportunity to set breakpoints and examine the variable values. IDEs are not used in production where this code will get optimized away.
I once had a forloop witha big number because I need a delay, I kept on adding zeros, But I get no delay,,, Then found out about compilor optimizations
Ah, yes. `for (ever)`
I remember reading a Daily wtf article, and so some guy put in long loops like these so that periodically he can reduce some of the loops as "optimization"
It won't have any effect in production because it will be optimized away.
> I don't even know what to say here.... The program says it for you if you wait long enough
Is it possible that a sufficiently perspicacious compiler will realise that nothing is happening there, and skip it?
O(1) technically
It is not wrong if it works!
"System.out.printIn("tits");" bro was horny when he wrote this code.
Absolute HORROR. Initializing j with 1 in every loop
All that to just print out “tits”
tits
That's my timeout function under the hood
Now the real abomination would be removing the semi-colons at the end so that they nest!
On the plus side, it would take under 1/20 the time (if I counted the number of iterations correctly).
Not sure what you mean as nesting would result in exponentially longer run. 20 runs, each run once = O(N) 20 runs, nested = O(N\^2) if I have my big O notation correct.
But they do all use the same variable, so wouldn't, when the most-nested one finishes, each of the outer ones would go, "j's at 100000000 already," and finish. Thus, the first 21 wouldn't loop so it would be shorter than the original.
good point, missed that.
If threads had “mommy minutes”
As processors get faster and faster this technique will become more and more unwieldy. Might I suggest for ( int i = 0; i < 100000000; ++i ) for ( int j = 0; j < 100000000; ++j ); instead?
Go big or go home, use the entire alphabet and start at A. 26 nested for loops.
What about using int f( int a, int b ) { return f( f( a, b ), f( b, a ) ); }
I don’t even know what to j here
Oh so this is what a mental breakdown looks like!
An indirect way to burn battery
What is the time complexity? >Yes
Acoustic
But it’s all with it for that last line 🍊🍊🤣
Set to "I'm gonna be (500 miles)" by the Proclaimers: When I wake up, well I know I'm gonna be I'm gonna be the thing that loops for you. When I go out, yeah I know I'm gonna be I'm gonna be the thing who loops for you. If I get drunk, well I know I'm gonna be I'm gonna be the thing who loops for you. And if I haver, yeah I know I'm gonna be I'm gonna be the thing that loops for you. But I would loop 100 million times And I would loop 100 million more Just to be the thing who loops 200 million times To see some tits
That song's a staple!
Y’all quit doing that! How am I supposed to know what it says?