1. source code speed question
- Posted by Lnettnay Apr 02, 2009
- 839 views
In DLL.E C_INT, C_LONG, etc. are constants initialized in HEX.
When using say a C_LONG does the program convert it to DECIMAL each time its used in the user's code or is it converted to DECIMAL only ONCE when it's defined as a constant ?
I know it is more convenient to use HEX in the source but wouldn't be faster to use all DECIMAL in the constants so no conversion would be required ?
2. Re: source code speed question
- Posted by bernie Apr 02, 2009
- 832 views
In DLL.E C_INT, C_LONG, etc. are constants initialized in HEX.
When using say a C_LONG does the program convert it to DECIMAL each time its used in the user's code or is it converted to DECIMAL only ONCE when it's defined as a constant ?
I know it is more convenient to use HEX in the source but wouldn't be faster to use all DECIMAL in the constants so no conversion would be required ?
I don't know where that name came from but this post was from me
3. Re: source code speed question
- Posted by jeremy (admin) Apr 02, 2009
- 810 views
I don't know where that name came from but this post was from me
That's pretty weird. It's a first we had that happen. I'll do some digging a bit later.
Jeremy
4. Re: source code speed question
- Posted by mattlewis (admin) Apr 02, 2009
- 827 views
In DLL.E C_INT, C_LONG, etc. are constants initialized in HEX.
When using say a C_LONG does the program convert it to DECIMAL each time its used in the user's code or is it converted to DECIMAL only ONCE when it's defined as a constant ?
I know it is more convenient to use HEX in the source but wouldn't be faster to use all DECIMAL in the constants so no conversion would be required ?
Bernie,
I'm not sure what you're asking. A number is a number. To the computer, it's a bunch of bits, neither decimal nor hexadecimal. The radix only affects the display of a number.
Perhaps its the sign that's the issue? Take a look at the docs for Atoms and Sequences. In particular:
Hex numbers are always positive, unless you add a minus sign in front of the # character. So for instance #FFFFFFFF is a huge positive number (4294967295), not -1, as some machine-language programmers might expect.
Matt
5. Re: source code speed question
- Posted by LarryMiller Apr 02, 2009
- 769 views
In DLL.E C_INT, C_LONG, etc. are constants initialized in HEX.
When using say a C_LONG does the program convert it to DECIMAL each time its used in the user's code or is it converted to DECIMAL only ONCE when it's defined as a constant ?
I know it is more convenient to use HEX in the source but wouldn't be faster to use all DECIMAL in the constants so no conversion would be required ?
I am quite certain that numeric constants are stored in an internal format, not decimal. Hex constants would be evaluated directly to this format. Any performance differences would be nill.
6. Re: source code speed question
- Posted by bernie Apr 02, 2009
- 828 views
I don't know where that name came from but this post was from me
That's pretty weird. It's a first we had that happen. I'll do some digging a bit later.
Jeremy
I went out of the house for a while and returned. Before I had left I was signed-in and had started that post. When I returned I completed the post and submitted it. When I submitted it; it posted it with that name Then on completion I looked up I was logout of OpenEuphoria.
7. Re: source code speed question
- Posted by bernie Apr 02, 2009
- 853 views
In DLL.E C_INT, C_LONG, etc. are constants initialized in HEX.
When using say a C_LONG does the program convert it to DECIMAL each time its used in the user's code or is it converted to DECIMAL only ONCE when it's defined as a constant ?
I know it is more convenient to use HEX in the source but wouldn't be faster to use all DECIMAL in the constants so no conversion would be required ?
Bernie,
I'm not sure what you're asking. A number is a number. To the computer, it's a bunch of bits, neither decimal nor hexadecimal. The radix only affects the display of a number.
Perhaps its the sign that's the issue? Take a look at the docs for Atoms and Sequences. In particular:
Hex numbers are always positive, unless you add a minus sign in front of the # character. So for instance #FFFFFFFF is a huge positive number (4294967295), not -1, as some machine-language programmers might expect.
Matt
Matt:
Because you are using a character by character scan of a number
For example using the same number:
You see a HEX number in the code as '#' '1' '2' 'B'
You see a DECIMAL number in the code as '2' '9' '9'
Which is faster to scan ?
8. Re: source code speed question
- Posted by DerekParnell (admin) Apr 02, 2009
- 837 views
In DLL.E C_INT, C_LONG, etc. are constants initialized in HEX.
When using say a C_LONG does the program convert it to DECIMAL each time its used in the user's code or is it converted to DECIMAL only ONCE when it's defined as a constant ?
I know it is more convenient to use HEX in the source but wouldn't be faster to use all DECIMAL in the constants so no conversion would be required ?
Because you are using a character by character scan of a number
For example using the same number:
You see a HEX number in the code as '#' '1' '2' 'B'
You see a DECIMAL number in the code as '2' '9' '9'
Which is faster to scan ?
They take the same time.
When "constant" is first seen in your program, Euphoria converts it to a number in machine-code format - it is no longer text. From then on, when your program uses that constant, it actually uses the ready-to-use machine-code number so it doesn't have to convert it each time.
There is no perfomance advantage between writing constants using decimal notation or hexadecimal notatation. The best bet is to use whatever is best for humans to read the code in. Note that to aid human reading of source code numbers, we have introduced the grouping character for numeric literals. You can now use the underscore character inside a number literal to group digits together to aid legibility. For example ...
constant BigHex = #0F04_4AE0, telephone = 02_555_1224, pie = 9.347_377_E-3
9. Re: source code speed question
- Posted by mattlewis (admin) Apr 02, 2009
- 843 views
Because you are using a character by character scan of a number
For example using the same number:
You see a HEX number in the code as '#' '1' '2' 'B'
You see a DECIMAL number in the code as '2' '9' '9'
Which is faster to scan ?
Unless you're scanning a lot of them, I doubt you'd ever notice the difference.
Matt
10. It's happened before.
- Posted by LonnyNettnay Apr 02, 2009
- 871 views
- Last edited Apr 03, 2009
I am LNettnay. I forgot my password for that account and now I use my full name. This happened once before and I mentioned it then but nobody responded. I was going to search for the post but search seems to have gone away AGAIN. :(
Lonny Nettnay
11. Re: It's happened before.
- Posted by jeremy (admin) Apr 02, 2009
- 860 views
- Last edited Apr 03, 2009
I am LNettnay. I forgot my password for that account and now I use my full name. This happened once before and I mentioned it then but nobody responded. I was going to search for the post but search seems to have gone away AGAIN. :(
Lonny Nettnay
Weird, very. Yes, search is gone again, I'm sorry. However, you can search at the bottom and it should find it OK. There was a security flaw found in the search and it has not been rewritten yet, but it'll come. I've just been focusing on 4.0 more than the forum. To some degree that's good, and others bad.
Jeremy