Чтобы завершить описанные выше методы, я попробовал вариант с файловым модулем:
import fileinput as fi
def filecount(fname):
for line in fi.input(fname):
pass
return fi.lineno()
И передал файл строк длиной 60 мил всем указанным выше методам:
mapcount : 6.1331050396
simplecount : 4.588793993
opcount : 4.42918205261
filecount : 43.2780818939
bufcount : 0.170812129974
Для меня немного неожиданно, что fileinput - это то, что плохо и масштабируется намного хуже, чем все другие методы ...
с очень простым примером из примера текстового поля WPF изестероидов:
, если вы смотрите на это в редакторе кода, строки, на которые вы хотите посмотреть, это: Строка 4 - ваша переменная Строка 33 - определение переменной в качестве текста для текстового блока [ 117]
#region XAML window definition
# Right-click XAML and choose WPF/Edit... to edit WPF Design
# in your favorite WPF editing tool
$adminname = "Guyver1"
$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="300"
ResizeMode="NoResize"
SizeToContent="Height"
Title="New Mail"
Topmost="True">
<Grid Margin="10,10,10,10" ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="0"
Margin="5">Please enter your details:
</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="1" Margin="5">$adminname
</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="2" Margin="5">Email
</TextBlock>
<TextBox
Name="TxtName"
Grid.Column="1"
Grid.Row="1"
Margin="5">
</TextBox>
<TextBox
Name="TxtEmail"
Grid.Column="1"
Grid.Row="2"
Margin="5">
</TextBox>
<StackPanel
Grid.ColumnSpan="2"
Grid.Row="3"
HorizontalAlignment="Right"
Margin="0,10,0,0"
VerticalAlignment="Bottom"
Orientation="Horizontal">
<Button
Name="ButOk"
Height="22"
MinWidth="80"
Margin="5">OK
</Button>
<Button
Name="ButCancel"
Height="22"
MinWidth="80"
Margin="5">Cancel
</Button>
</StackPanel>
</Grid>
</Window>
"@
#endregion
#region Code Behind
function Convert-XAMLtoWindow
{
param
(
[Parameter(Mandatory=$true)]
[string]
$XAML
)
Add-Type -AssemblyName PresentationFramework
$reader = [XML.XMLReader]::Create([IO.StringReader]$XAML)
$result = [Windows.Markup.XAMLReader]::Load($reader)
$reader.Close()
$reader = [XML.XMLReader]::Create([IO.StringReader]$XAML)
while ($reader.Read())
{
$name=$reader.GetAttribute('Name')
if (!$name) { $name=$reader.GetAttribute('x:Name') }
if($name)
{$result | Add-Member NoteProperty -Name $name -Value $result.FindName($name) -Force}
}
$reader.Close()
$result
}
function Show-WPFWindow
{
param
(
[Parameter(Mandatory=$true)]
[Windows.Window]
$Window
)
$result = $null
$null = $window.Dispatcher.InvokeAsync{
$result = $window.ShowDialog()
Set-Variable -Name result -Value $result -Scope 1
}.Wait()
$result
}
#endregion Code Behind
#region Convert XAML to Window
$window = Convert-XAMLtoWindow -XAML $xaml
#endregion
#region Define Event Handlers
# Right-Click XAML Text and choose WPF/Attach Events to
# add more handlers
$window.ButCancel.add_Click(
{
$window.DialogResult = $false
}
)
$window.ButOk.add_Click(
{
$window.DialogResult = $true
}
)
#endregion Event Handlers
#region Manipulate Window Content
$window.TxtName.Text = $env:username
$window.TxtEmail.Text = 'test@test.com'
$null = $window.TxtName.Focus()
#endregion
# Show Window
$result = Show-WPFWindow -Window $window
#region Process results
if ($result -eq $true)
{
[PSCustomObject]@{
EmployeeName = $window.TxtName.Text
EmployeeMail = $window.TxtEmail.Text
}
}
else
{
Write-Warning 'User aborted dialog.'
}
#endregion Process results