We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Temp int + const int is faster than const int + temp int:
'1+1' printNl. Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+1] ] ;printNl . Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+1] ] ;printNl . Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+1] ] ;printNl . '' printNl. 'x+x' printNl. Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+x] ] ;printNl . Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+x] ] ;printNl . Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+x] ] ;printNl . '' printNl. 'x+1' printNl. Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+1] ] ;printNl . Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+1] ] ;printNl . Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| x+1] ] ;printNl . '' printNl. '1+x' printNl. Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+x] ] ;printNl . Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+x] ] ;printNl . Timer millisecondsToRun: [ 1 to: 1000000 do: [:x| 1+x] ] ;printNl . '' printNl.
1+1 677 678 679 x+x 674 673 684 x+1 650 648 653 1+x 695 696 697
The text was updated successfully, but these errors were encountered:
What is the actual proposal here? Reorder the operands or patch the code inserting more efficient instruction?
Anyway, I don't think it's a very important optimization :) P.S.: What are the timings for the equivalent JIT execution?
Sorry, something went wrong.
The problem is: there is a huge difference in performance between 'x+1' and '1+x'. Take a look at the bytecode below:
METHOD Undefined main " initialize classes " Char initialize. " x+1 " [:x| x+1]. '' printNl. " 1+x " [:x| 1+x]. File fileIn: '../image/disasm.st'. Undefined methods at: #main; disassemble. ^nil. !
0000 PushLiteral 0 0001 MarkArguments 1 0002 SendMessage initialize 0003 DoSpecial popTop 0004 PushBlock 0007 PushTemporary 2 0008 PushConstant 1 0009 SendBinary + 0010 DoSpecial stackReturn 0011 DoSpecial popTop 0012 PushLiteral 2 0013 MarkArguments 1 0014 SendMessage printNl 0015 DoSpecial popTop 0016 PushBlock 0019 PushConstant 1 0020 PushTemporary 2 0021 SendBinary + 0022 DoSpecial stackReturn 0023 DoSpecial popTop 0024 PushLiteral 4 0025 PushLiteral 5 0026 MarkArguments 2 0027 SendMessage fileIn: 0028 DoSpecial popTop 0029 PushLiteral 7 0030 MarkArguments 1 0031 SendMessage methods 0032 PushLiteral 9 0033 MarkArguments 2 0034 SendMessage at: 0035 DoSpecial duplicate 0036 MarkArguments 1 0037 SendMessage disassemble 0038 DoSpecial popTop 0039 PushConstant nil 0040 DoSpecial stackReturn 0041 DoSpecial popTop 0042 DoSpecial selfReturn
No branches or pull requests
Temp int + const int is faster than const int + temp int:
The text was updated successfully, but these errors were encountered: