Schrift
[thread]937[/thread]

Timer liefert stark abweichende Werte

Leser: 1


<< >> 4 Einträge, 1 Seite
mr-sansibar
 2007-06-08 12:56
#151 #151
User since
2006-04-13
90 Artikel
BenutzerIn
[default_avatar]
Hi !
Ich habe einen Timer eingebaut in mein Skript jedoch bekomme ich jedes mal stark abweichende Werte zurück.
Arbeite mit dem Modul Time::HiRes

Im Perl-Skript es geht es darum, dass ich 3 Files lese und nacheinader verarbeite.
Mir ist aber aufgefallen, das das skriupt für die bearbeitung 3 sec oder 1 braucht.
vorran liegt das. obwohl es sich immer um die selben datengröße und struktur handelt.

Code: (dl )
1
2
3
4
5
6
7
8
use Time::HiRes qw(gettimeofday);

my $t0 = gettimeofday();
"Meine Operationen"
my $t1 = gettimeofday();

my $elapsed = $t1 - $t0;
print "$elapsed Sekunden \n";


danke für eure tips !!!\n\n

<!--EDIT|mr-sansibar|1181293079-->
pq
 2007-06-08 13:42
#152 #152
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
Time::HiRes liefert dir die zeit. warum das skript manchmal lange braucht und manchmal
nicht, kann dir aber auch Time::HiRes nicht sagen, und wir auch nicht. du zeigst weder
code, noch zeigst du, was du als output bekommst.
deine aufgabe ist es jetzt, selbst herauszufinden, an welcher stelle es genau hakt.
im übrigen verwende ich immer:
Code: (dl )
1
2
my $t0 = [gettimeofday];
my $elapsed = tv_interval($t0);
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem
mr-sansibar
 2007-06-15 16:42
#153 #153
User since
2006-04-13
90 Artikel
BenutzerIn
[default_avatar]
So sieht mein Code aus!
vielleicht kannst du ja sehen voran es liegt.
mir ist aufgefallen dass ich für das parsen 10 Sekunden brauche für 1 MB.
kann man den code eventuell performanter machen ?
Danke für eure Tips

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use strict;
use warnings;
use Getopt::Long;
use IO::File;
use File::Glob;
use Data::Dumper;
use File::Find;
use Time::HiRes qw(gettimeofday);

# the cmd-line-arg --output
my $output = 0;
GetOptions(
'output=s' => \$output,
);

my $fh1 = new IO::File;
my $fh2 = new IO::File;
my $fh3 = new IO::File;


my $write_context = "context.csv";
my $write_message = "message.csv";


my @logfilelist =glob("*.log");
my @array;
my $line;
my $counter=0;
my $item=0;
my $MessageFound=0;
my @list;

my $t0 = gettimeofday();


foreach my $file(@logfilelist) {
my $tmp_file=substr($file,0,-4);
$fh1->open("> h:/$tmp_file-$write_context") || die "$write_context kann nicht erzeugt werden";
$fh2->open("> h:/$tmp_file-$write_message")|| die " $write_message kann nicht erzeugt werden";
$fh3->open("<$file") || die "$file konnte nicht zum lesen geöffnet werden";

while(<$fh3>)
{
if(/Context:/)
{
$line = chomp($_);
$line= substr($_,10,length($_));
@array = split(/ /, $line);
$line='';
#print $fh1 Data::Dumper->Dump([\@array], [' split / /']);
#print $fh1 "$counter;",@array,"\n"
#print $fh1 @array, "\n";

foreach my $idx (0 .. 5) {
$array[$idx].=";"
}

if($array[2] ne ";")
{
$counter++;
#$MessageFound=0;
#print $fh1 Data::Dumper->Dump([\@array], [' split / /']);
print $fh1 "$counter;",@array,"\n"
}
}

if(/Message:/ || $MessageFound)
{
if($array[2] ne ";")
{
$MessageFound=1;
if($_ =~ /^\n/)
{
chomp($line);
$line .= "/ende\n";
print $fh2 "$counter|$line";
$line = '';
$MessageFound=0;
}
else
{ chomp($_);
$line .= $_
};
}
}
}

}


$fh1->close;
$fh2->close;
my $t1= gettimeofday();
my $elapsed = $t1 - $t0;
print "$elapsed Sekunden \n";
GwenDragon
 2007-06-15 19:45
#154 #154
User since
2005-01-17
14761 Artikel
Admin1
[Homepage]
user image
Performater ist es, wenn du bei der Suche nach Inhalten index() verwendest; du brauchst ja kein Regex, da ist m// nämlich langsamer.

Quote
index STR,SUBSTR,POSITION
index STR,SUBSTR
The index function searches for one string within another, but without the wildcard-like behavior of a full regular-expression pattern match. It returns the position of the first occurrence of SUBSTR in STR at or after POSITION. If POSITION is omitted, starts searching from the beginning of the string. The return value is based at 0 (or whatever you've set the $[ variable to--but don't do that). If the substring is not found, returns one less than the base, ordinarily -1.

perldoc -f index

und Strings rausschneiden mit substr()
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
substr EXPR,OFFSET,LENGTH,REPLACEMENT
substr EXPR,OFFSET,LENGTH
substr EXPR,OFFSET
Extracts a substring out of EXPR and returns it. First character is at offset 0, or whatever you've set $[ to (but don't do that). If OFFSET is negative (or more precisely, less than $[), starts that far from the end of the string. If LENGTH is omitted, returns everything to the end of the string. If LENGTH is negative, leaves that many characters off the end of the string.

You can use the substr() function as an lvalue, in which case EXPR must itself be an lvalue. If you assign something shorter than LENGTH, the string will shrink, and if you assign something longer than LENGTH, the string will grow to accommodate it. To keep the string the same length you may need to pad or chop your value using sprintf.

If OFFSET and LENGTH specify a substring that is partly outside the string, only the part within the string is returned. If the substring is beyond either end of the string, substr() returns the undefined value and produces a warning. When used as an lvalue, specifying a substring that is entirely outside the string is a fatal error. Here's an example showing the behavior for boundary cases:
my $name = 'fred';
substr($name, 4) = 'dy'; # $name is now 'freddy'
my $null = substr $name, 6, 2; # returns '' (no warning)
my $oops = substr $name, 7; # returns undef, with warning
substr($name, 7) = 'gap'; # fatal error

An alternative to using substr() as an lvalue is to specify the replacement string as the 4th argument. This allows you to replace parts of the EXPR and return what was there before in one operation, just as you can with splice().

perldoc -f substr\n\n

<!--EDIT|GwenDragon|1181922473-->
<< >> 4 Einträge, 1 Seite



View all threads created 2007-06-08 12:56.