1. source code speed question

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 ?

new topic     » topic index » view message » categorize

2. Re: source code speed question

said...

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: source code speed question

bernie said...

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

new topic     » goto parent     » topic index » view message » categorize

4. Re: source code speed question

Bernie said...

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:

TFM said...

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

new topic     » goto parent     » topic index » view message » categorize

5. Re: source code speed question

Lnettnay said...

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.

new topic     » goto parent     » topic index » view message » categorize

6. Re: source code speed question

jeremy said...
bernie said...

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.

new topic     » goto parent     » topic index » view message » categorize

7. Re: source code speed question

mattlewis said...
Bernie said...

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:

TFM said...

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 ?

new topic     » goto parent     » topic index » view message » categorize

8. Re: source code speed question

bernie said...
Bernie said...

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 
          
new topic     » goto parent     » topic index » view message » categorize

9. Re: source code speed question

bernie said...

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

new topic     » goto parent     » topic index » view message » categorize

10. It's happened before.

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

new topic     » goto parent     » topic index » view message » categorize

11. Re: It's happened before.

LonnyNettnay said...

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu