1. time() not returning Integer

If I set a variable such as a = time() and set a as an integer it returns
a type check error. By using printf(fn, "%f", a) I was able to get it to 
return even decimals. It just won't return an odd number!

new topic     » topic index » view message » categorize

2. Re: time() not returning Integer

Tristen Wilson wrote:
> 
> If I set a variable such as a = time() and set a as an integer it returns
> a type check error. 

The time() function returns an atom and not an integer. In other words, its
value can be fractions of a second. It does not return the Time Of Day. It is
used for finding elapsed time.

  atom Start
  atom Stop

  Start = time()
  DoSomething()
  Stop = time()
  printf(1, "Duration=%f", Stop - Start)


> By using printf(fn, "%f", a) I was able to get it to 
> return even decimals. It just won't return an odd number

Show us what you mean by giving examples that you actually used and their
results.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

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

3. Re: time() not returning Integer

Derek Parnell wrote:
> Show us what you mean by giving examples that you actually used and their
> results.
> 
> -- 
> Derek Parnell
> Melbourne, Australia
> Skype name: derek.j.parnell
My code is below
include get.e
include misc.e

integer start, stop
procedure loop()
start = time()
-- Time to start some long loop
for i = 0 to 100000 do
puts(2, "At loop:")
? i
clear_screen()
end for
stop = time() - start
printf(2, "Total time Elapsed: %d", stop)
sleep(2)
end procedure
loop()

Complete Error Report:
C:\DOCUME~1\exec\Desktop\TIMEER~1.TXT:6 in procedure loop() 
type_check failure, start is 0.06 
    i = <no value>

... called from C:\DOCUME~1\exec\Desktop\TIMEER~1.TXT:17 


Global & Local Variables

 \EUPHORIA\include\get.e:
    input_file = <no value>
    input_string = <no value>
    string_next = <no value>
    ch = <no value>

 \EUPHORIA\include\misc.e:
    pretty_end_col = <no value>
    pretty_chars = <no value>
    pretty_start_col = <no value>
    pretty_level = <no value>
    pretty_file = <no value>
    pretty_ascii = <no value>
    pretty_indent = <no value>
    pretty_ascii_min = <no value>
    pretty_ascii_max = <no value>
    pretty_line_count = <no value>
    pretty_line_max = <no value>
    pretty_dots = <no value>
    pretty_fp_format = <no value>
    pretty_int_format = <no value>
    pretty_line = <no value>

 C:\DOCUME~1\exec\Desktop\TIMEER~1.TXT:
    start = 0.06
    stop = <no value>

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

4. Re: time() not returning Integer

Tristen Wilson wrote:

It might help if you actually took the time to understand the help that you are
being given. If after trying to work through that, you are still not getting it,
then ask a NEW and DIFFERENT question that refines your issue rather than a
pleading "help me!". It idea is to get people to sympathize with your plight and
your not quite achieving that yet.

I'll say it again ...  time() returns an atom and not an integer.

So therefore the variable you assign the result to must be an atom and not an
integer.

You code should be more like ...

include get.e
include misc.e

atom start, stop   -- NOT INTEGER
procedure loop()
start = time()
-- Time to start some long loop
puts(2, "At loop:")  -- OUTSIDE THE LOOP
for i = 0 to 100000 do
? i
end for
clear_screen() -- OUTSIDE THE LOOP
stop = time() - start
printf(2, "Total time Elapsed: %f", stop)  -- NOT %d
sleep(2)
end procedure
loop()


By the way, this took 20.68 seconds on my machine.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

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

5. Re: time() not returning Integer

> By the way, this took 20.68 seconds on my machine.


The loop only took 7.47 Seconds on my machine.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu