date problem

L

Lukas Mai

Purl Gurl replied to itself:
(shoveled out mule manure)
int main() no int return in body to produce a message,
--------------------Configuration: test1 - Win32 Debug--------------------
Compiling...
test1.cpp
C:\Visual_c\MSDev98\MyProjects\test1.cpp(14) : warning C4508: 'main' : function should return a value; 'void' return type assumed
"void return type assumed"
void main(void)

int main()
{ return 0; }

That's why I said MSVC++ 6 is obsolete. It simply isn't a conforming C++
implementation. See 3.6.1 #5 [basic.start.main]:

| A return statement in main has the effect of leaving the main function
| (destroying any objects with automatic storage duration) and calling
| exit with the return value as the argument. If control reaches the end
| of main without encountering a return statement, the effect is that of
| executing return 0;
int main()
{
exit(1);

Note that an exit status of 1 is unportable; the only portable values
are 0 or EXIT_SUCCESS for success and EXIT_FAILURE for failure (the
latter two are macros defined in said:
return 0; /* never executed runtime is perfect */
}
Would you like to try again, Bozo?

Would you like to consult the C++ standard, phallic symbol of atrocity?
using namespace std
std::ctime & std::printf
--------------------Configuration: test2 - Win32 Debug--------------------
Compiling...
test2.cpp
C:\Visual_c\MSDev98\MyProjects\test2.cpp(4) : error C2871: 'std' : does not exist or is not a namespace
C:\Visual_c\MSDev98\MyProjects\test2.cpp(11) : error C2653: 'std' : is not a class or namespace name
C:\Visual_c\MSDev98\MyProjects\test2.cpp(13) : error C2653: 'std' : is not a class or namespace name
Error executing cl.exe.
test2.obj - 3 error(s), 0 warning(s)
Would you like to try again, Bozo?

Did you actually include said:
When you troll, fate almost always has it
you end up flaunting your ignorance, which
is most logical because trolls are ignorant.

FYI: C++ (unlike Perl) isn't an empirical science. Your "compiler" doesn't
define the language.
Purl Gurl

Frank
 
L

Lukas Mai

Purl Gurl schrob:
Lukas Mai continues to troll: [...]
(shoveled out mule manure)

"mule manure" = relevant context?
Do you actually know anything about programming in C/C++ language?

There is no "C/C++ language". You lose.[1]
Based on what I read you know diddly-squat about
programming in C/C++ but are quite the expert at
writing laughable troll articles.

I know quite a bit about programming in C, and I know less about
programming in C++.
Your problem is this. You have no seasoned experience
programming in C/C++ and your real problem is you are
completely faking it hoping others will not notice,
as I have with your first article.

So you don't know anything about standard C++?
Such childish behavior is yours.

A WINNER IS YOU!
Purl Gurl

Lukas
[1] http://home.cs.tum.edu/~mai/poly.sh.pl.cc.c.txt
This little hack should correctly report if it was compiled with
a C or C++ compiler. It even recognizes Perl, which makes it almost
on-topic.
 
G

Gabkin

Tapani said:
Interesting. In HP-UX date +%N gives emperor name (for Japanese
calendar), not nanoseconds... it doesn't seem to be defined
at all by POSIX. But it does seem to work with Gnu date.




That is also non-POSIX, it assumes bash or ksh93 or similar.
But with Gnu date you can simply use "%-1N" to get only the first
digit of nanoseconds (= deciseconds).
Aha!
Thanks
The answer I was looking for was
"date +%Y%m%d%H%M%S%-1N"
which accomplishes exactly what i wanted.
Super high precision isnt entirely necessary as this is just going to be
used as a unique number which must be 15 digits long, not 14. I was told
that the standard for this system is YYYYMMDDHHMMSSS.

Once again, thank you for the prompt and useful answer!
 
G

Gabkin

Purl said:
At a DOS command line, test this hack,

date.|time

That will return milliseconds along with wording you
really do not need. You will find adapting this to
Perl to be fun, with a need to send a ^D signal.
ugh!
no thanks.
I have already found out the inadequacies of the win32 'date' command
firsthand and have no desire to use it for anything.
As it turns out a better method is to use the following switches for GNU
date...
"date +%Y%m%d%H%M%S%-1N"
it seems the "-1%N" returns only the first digit of the nanoseconds
which accomplishes exactly what I want.
Time High Resolution is not compatible with Win32.
I do not know if cygwin affords needed functions
to support Time High Resolution under Win32.

Purl Gurl
--
As it turns out I am already using Time::HiRes in my perl program so
that I can time execution speed.
Execution speed is very fast, in case you were in any doubt, 5 minutes
for a program which would have taken Visual basic 2-10 hours. Visual
basic (and COBOL) is the in-house preferred tool for jobs like this
(text-manipulation).

Speaking of win32 and Time::HiRes, I have activestate perl installed and
I also have Cygwins perl installed as well.
I tried the following...

<CMD.EXE.>
C:\>perldoc Time::Hires
No documentation found for "Time::Hires".

C:\>
</CMD.EXE.>
So you're (partially) right about Time:HiRes not being supported under
Win32. However I am using Time:HiRes with Cygwin's perl and it works
just fine.

So I tried the same under CygWin and it has the documentation but with
control chars inserted like so...

<perldoc>
ESC[1mNAMEESC[0m
Time::HiRes - High resolution alarm, sleep, gettimeofday, interval
timers
</perldoc>
with the 'ESC' highlighted.Interestingly, it also sets the window title
to 'c' under 'cmd.exe'.
The control characters are also present under rxvt but the title remains
my custom title.
Does anyone know why those control/escape characters are there and how I
can get rid of them?
 
G

Gabkin

Gunnar said:
Gabkin said:
I need to generate a date in the format YYYYMMDDHHMMSSS for a perl
program. (Note the _three_ digits allocated for Seconds, not the
usual _two_)


sub timestamp {
require Time::HiRes;
my ($epoch, $micro) = Time::HiRes::gettimeofday();
my ($s, $mi, $h, $d, $mo, $y) = (localtime $epoch)[0..5];
sprintf '%d%02d%02d%02d%02d%02d%.0f',
$y+1900, $mo+1, $d, $h, $mi, $s, $micro/100000
}

print timestamp();

Outputs e.g.:
200407112303299

P.S.
http://groups.google.com/[email protected]

Grooh!
I suppose that may do the trick and that is kind of what i would have
done if I hadn't found this...

"date +%Y%m%d%H%M%S%-1N" (GNU date of course!)

The "-1%N" returns only the first digit on nanoseconds.
Once again, those cunning GNU hackers anticipated my needs!

Thanks all the same
 
G

Gunnar Hjalmarsson

Gabkin said:
Speaking of win32 and Time::HiRes, I have activestate perl
installed and I also have Cygwins perl installed as well.
I tried the following...

<CMD.EXE.>
C:\>perldoc Time::Hires
No documentation found for "Time::Hires".

C:\>
</CMD.EXE.>
So you're (partially) right about Time:HiRes not being supported
under Win32.

I fail to see how that tells you anything about whether Time::HiRes is
compatible with Win32. It merely indicates that Time::HiRes is not
included in the ActiveState distribution.

I'm running the IndigoPerl Perl package on W98 (not Cygwin),
Time::HiRes is available, and the code I suggested at
http://groups.google.com/[email protected]
was tested on W98 only.
 
G

Gabkin

Gabkin said:
I need to generate a date in the format YYYYMMDDHHMMSSS for a perl
program. (Note the _three_ digits allocated for Seconds, not the usual
_two_)

date +%Y%m%d%H%M%S will give YYYYMMDDHHMMSS which is close but it doesnt
have that extra S at the end.

I am using "date (sh-utils) 2.0.15" and "perl, v5.8.2" on Cygwin.

Is there a quick and easy way of getting that extra degree of precision
with 'date'?
Failing that, a way to get it with perl?

Thanks
Update: the correct answer is
"date +%Y%m%d%H%M%S%-1N"

However as it turns out, even this was inadequate as perl executed the
task too rapidly. This is basically what I am thinking of using...
(feel free to criticize my code)

<PERL>

#!/usr/local/bin/perl
for(1..15000) {
print(&getUnique15DigitDate(),"\n");
}
exit;

sub getUnique15DigitDate() {
select(undef,undef,undef,0.1);
open(DATE,'date +%Y%m%d%H%M%S%N| ');
my $date=<DATE>;close DATE;
$date =~ s/\n|\-//;
return substr($date,0,15);
}
</PERL>

Basically I force the program to 'wait' 0.1 seconds every time before
generating a timestamp, to ensure that it is unique.

This should work but it has the unfortunate side-effect of pushing up
execution speed dramatically.This script alone should take 15 minutes to
complete. The full program takes 5 minutes, a huge improvement over
traditional in-house methods using VB, which normally take several
hours. I chose 15000 for this script because I know for a fact that my
program will loop 15472 times, thus using waiting 0.1 seconds everytime
could push up execution speed by just over 25 minutes, a 500% increase!

Other methods:

use 'int(rand(9))' for the 15th digit and use a normal 14 digit
timestamp for the rest.

OR

Use an incremented counter for the 15th digit and only use the last
digit of that counter.
Is there a modulus function in perl?
I can't find one....

Suggestions, anyone?
 
G

Gabkin

Basically I force the program to 'wait' 0.1 seconds every time before
generating a timestamp, to ensure that it is unique.

This should work but it has the unfortunate side-effect of pushing up
execution speed dramatically.This script alone should take 15 minutes to
complete. The full program takes 5 minutes, a huge improvement over
traditional in-house methods using VB, which normally take several
hours. I chose 15000 for this script because I know for a fact that my
program will loop 15472 times, thus using waiting 0.1 seconds everytime
could push up execution speed by just over 25 minutes, a 500% increase!

actually I timed it and it took 592 seconds(almost 10 minutes), which is
still quite the increase!
 
A

A. Sinan Unur

So I tried the same under CygWin and it has the documentation but with
control chars inserted like so...

<perldoc>
ESC[1mNAMEESC[0m
Time::HiRes - High resolution alarm, sleep, gettimeofday,
interval timers
</perldoc>
with the 'ESC' highlighted.Interestingly, it also sets the window
title to 'c' under 'cmd.exe'. The control characters are also present
under rxvt but the title remains my custom title. Does anyone know why
those control/escape characters are there and how I can get rid of
them?

Those are ANSI escape sequences. In the above, NAME is supposed to be
displayed in bold. I am not sure why the output is not being displayed
properly as man seems to work just fine.

You can use perldoc -t Time::HiRes in the meantime.
 
A

A. Sinan Unur

I am going to suggest:

http://www.catb.org/~esr/faqs/smart-questions.html#explicit

....
Update: the correct answer is
"date +%Y%m%d%H%M%S%-1N"

However as it turns out, even this was inadequate as perl executed the
task too rapidly. This is basically what I am thinking of using...
(feel free to criticize my code)

The questions is: Do you just need consecutive 15 digit numbers or do
these have to be the date?

If your program is going to run continuously for less than a month, %Y%m
do nothing for you in terms of ensuring uniqueness. How about shaving of
the year digits and adding some more nanoseconds?

If you explained exactly what you are doing, it would be far easier help
you.
#!/usr/local/bin/perl
for(1..15000) {
print(&getUnique15DigitDate(),"\n");
}
exit;

See perldoc perlsub for why getUnique15DigitDate() is preferable to
&getUnique15DigitDate().
I chose 15000 for this script because I know for a fact that my
program will loop 15472 times, thus using waiting 0.1 seconds
everytime could push up execution speed by just over 25 minutes, a
500% increase!

ITYM 'execution time'.
Is there a modulus function in perl?
I can't find one....

perldoc perlop
 
J

John W. Kennedy

Peter said:
Then what do you mean by "cpp"? I have never seen "cpp" mean
anything but the C preprocessor, which isn't relevant here.

In the Windows world, it is not unusual for C++ source files to be named
example.cpp, since the Unix convention of naming them example.C won't work.

To call the /language/ "cpp", however, is yet another of PG's -- mmmm --
quaint -- usages.

(Chaucerians have my permission to have fun with the above.)
 
A

A. Sinan Unur

....


My code will compile with either a .c extension or a .cpp extension.
However, none of you know enough about C language to realize this,
just as a troll here flaunted his ignorance about using namespaces.


This is completely off-topic and I apologize.

In the *nix world, .C and .c are different extensions. .C stands for C++
and .c stands for C source.

When a Microsoft or Borland compiler sees source code with the .cpp
extension, it assumes that the code is C++.

Consider the following code:

#ifdef __cplusplus
#include <cstdio>
#else
#include <stdio.h>
#endif

int main() {
#ifdef __cplusplus
std::puts("C++\n");
#else
puts("C\n");
#endif
return 0;
}

First save this in a file called t.cpp:

C:\Home> bcc32 t.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
t.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

C:\Home> t
C++

C:\Home> ren t.cpp t.c

C:\Home> bcc32 t.c
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
t.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

C:\Home> t
C
 
G

Gunnar Hjalmarsson

Gabkin said:
This is basically what I am thinking of using... (feel free to
criticize my code)

Basically I force the program to 'wait' 0.1 seconds every time
before generating a timestamp, to ensure that it is unique.

This should work but it has the unfortunate side-effect of pushing
up execution speed dramatically.

Talking about efficiency, and since you apparently are inclined to
choose a GNU solution before a pure Perl ditto, I got curious, so I
made a benchmark:

use Benchmark 'timethese';
timethese( 50000, {
GNU => sub {
#select(undef,undef,undef,0.1);
open(DATE,'date +%Y%m%d%H%M%S%N| ');
my $date=<DATE>;close DATE;
$date =~ s/\n|\-//;
return substr($date,0,15);
},
HiRes => sub {
require Time::HiRes;
my ($epoch, $micro) = Time::HiRes::gettimeofday();
$micro = sprintf '%.0f', $micro/100000;
$epoch ++ if $micro == 10;
my ($s, $mi, $h, $d, $mo, $y) = (localtime $epoch)[0..5];
sprintf '%d%02d%02d%02d%02d%02d%d',
$y+1900, $mo+1, $d, $h, $mi, $s, $micro % 10
},
} );

In the code above, I have commented out the select() statement. This
is the result:

Benchmark: timing 50000 iterations of GNU, HiRes...
GNU: 133 wallclock secs
(10.77 usr 25.30 sys + 42.74 cusr 66.87 csys = 145.68 CPU)
@ 1386.19/s (n=50000)
HiRes: 1 wallclock secs
( 1.37 usr + 0.08 sys = 1.45 CPU)
@ 34482.76/s (n=50000)

The pure Perl solution appears to be about ( 34483/1386 = ) 25 times
faster.
Other methods:

Suggestions, anyone?

I think you have already got a hint or two, if you read the thread
carefully. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top