wish i++, i+=, i--, --i, ++i, i&= etc..

ivan.tellez

Active Member
Licensed User
Longtime User
Have you seen any performance issues? In almost all cases the performance is the same as (well written) Java apps.

Maybe its not really a real performance issue, but I was inspired by:

I remember a long time ago that the syntax, like +=, was done because compilers at the time could be made more efficient.

So i did some tests. I wrote some code using sums and increments, first in a Java Lib, then in B4A, the results were really conclusive. Java code in the lib was faster than B4A (tested in large loops).
For example a simple code in java:
B4X:
int z;
z++;
And then tested in B4A code
B4X:
Dim z as Int
z = z + 1
Code in java was 60% Faster.
Then just for curiosity tested
B4X:
Dim z as Int
z = z + "1"
Code in java was 37,000% Faster.


So, maybe could be more room for a new set of asigment operations with a more specific and optimized behavior (for example avoiding the implicit type convertion, only working if the operands are the same data type.


:D
 

picenainformatica

Active Member
Licensed User
Longtime User
I think, with the market speed we have nowdays, that the more important thing is time to market. Other questions are relative. With B4A we have a lightspeed tool.
 

keirS

Well-Known Member
Licensed User
Longtime User
Have you seen any performance issues? In almost all cases the performance is the same as (well written) Java apps.

Most performance issues I have had are related to processing on the main thread. Most of those are to do with complex SQL queries. I have solved these by creating my own SQL library which gives me the ability to run queries on different threads. When I have finished writing a lazy loading cursor class I shall be releasing another version of my SQLExtended library with these features.
 

LucaMs

Expert
Licensed User
Longtime User
Most performance issues I have had are related to processing on the main thread. Most of those are to do with complex SQL queries. I have solved these by creating my own SQL library which gives me the ability to run queries on different threads. When I have finished writing a lazy loading cursor class I shall be releasing another version of my SQLExtended library with these features.


Are you sure you run the same query in the main thread directly in Java and have obtained higher response times?

I do not very much.


Anyway, this thread annoys me, "Unwatch" is a good solution :D
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Most performance issues I have had are related to processing on the main thread. Most of those are to do with complex SQL queries. I have solved these by creating my own SQL library which gives me the ability to run queries on different threads. When I have finished writing a lazy loading cursor class I shall be releasing another version of my SQLExtended library with these features.
The SQL library supports asynchronous execution of commands and queries. See Asynchronous queries section here: http://www.b4x.com/android/forum/threads/sql-tutorial.6736/#content
 

Beja

Expert
Licensed User
Longtime User
-1

C & J people want to enter from the window huh! No way..
Next time someone will have a wish to eliminate the +1 altogether.

folks! forget ++
 

keirS

Well-Known Member
Licensed User
Longtime User
The SQL library supports asynchronous execution of commands and queries. See Asynchronous queries section here: http://www.b4x.com/android/forum/threads/sql-tutorial.6736/#content

Yes I know. For me the problem with ExecNonQueryBatch is that it doesn't give any feedback. I need to know the row id of inserted records and the count for updates and deletes. I would have to call ExecNonQueryBatch with one statement and then execute a query with either the changes() function or the last_insert_rowid() function. I think that would be rather counter productive and take more time than running everything on the main thread. So I wrote my own which gives me the feedback I need.
 

MaFu

Well-Known Member
Licensed User
Longtime User
I like this old animal called KEdit (came from the IBM mainframe world) and there are things I can do quicker in it that I cannot even do in other editors.
:D me too, KEdit rocks
 

ivan.tellez

Active Member
Licensed User
Longtime User
Can you post the java code? If you are not parsing the string like your B4A code does then your comparison is wrong.

Hi, Im very sorry if i didnt explain myself. The 37,000% "Faster" java code is using only INTs without parsing a string. I know this is not a "fair" comparisson, but that was the point of the wish, adding the operators to have a chance to make them behave "different" than the current ones (for example not auto casting types and maybe more optimized).

As you said, "Adding features to a programming language should be done very carefully as it is a one way direction. You cannot later remove them."

Current operator cant change, but new ones (+=, -=, etc) could add support for programming some more robust app without deppending on lib creation.


By the way, testing the "fair" java code (parsing an string) , java code its 3x times faster (tested in large loops to se the difference):

B4A Code
B4X:
z = z + "1"

Java Code
B4X:
foo = Integer.parseInt("1");
z = z + foo;
 

Thraka

Member
Licensed User
Longtime User
At minimum I would rather have += That still saves a lot of time and isn't just for a single thing like ++ is. ++ only gives you an increment and there is nothing else you can do with it. += allows you to put in any value, much more useful. (same for -=)
 

Nerdworld

Member
Licensed User
Longtime User
As i remember, some other basic languages (DarkBasic?) at least had an "Increment"/"Decrement"-method, like:

B4X:
Dim a As Int = 5
Inc a ' 6
Inc a ' 7
Dec a ' 6
Dec a ' 5
 

yazak

Member
Licensed User
Longtime User
Another basic I use Pure basic does it nice and simple

long form
a=a+1
short form is
a+1

Short form is faster as just adds 1 to a memory location so is faster
and Long form needs to load a add 1 then save a back to memory location.

But as Pure basic creates fast executable's its useful for speed in loops
but as for B4A unless there is a speed advantage to be made in java with shorter form may as well stick with a=a+1.
 
Last edited:

sorex

Expert
Licensed User
Longtime User
I think the inc/a+1 is only usefull speedwise if you compile it straight to assembler which is not the case with java, it's tokenized stuff.

still, abbrevations like this are always handy.
 

Troberg

Well-Known Member
Licensed User
Longtime User
++x and x++ also have some situations where it's not entirely obvious what will happen. Example:

a+++b

Is that a plus a pre-incremented b or is it post-incremented a plus b?

I don't actually mind the ++ notation, but it has some drawbacks.

Another nice shortcut for the most common use is the += operator, such as x+=1 to increment x by 1. Less likely to cause confusion, and more flexible.
 
Top