我想知道从C迁移到shell脚本的程序性能会有多糟糕.
我有密集的I/O操作.
例如,在C中,我从文件系统文件中读取循环并写入另一个文件系统文件.我正在接受每一行的部分而没有任何一致的关系.我是用指针做的.一个非常简单的程序.
在Shell脚本中,要移动一行,我正在使用${var:(char):(num_bytes)}.在我完成处理每一行后,我只是将它连接到另一个文件.
"$out" >> "$filename"
Run Code Online (Sandbox Code Playgroud)
该程序执行以下操作:
while read line; do
out="$out${line:10:16}.${line:45:2}"
out="$out${line:106:61}"
out="$out${line:189:3}"
out="$out${line:215:15}"
...
echo "$out" >> "outFileName"
done < "$fileName"
Run Code Online (Sandbox Code Playgroud)
问题是,C需要半分钟来处理400MB文件,而shell脚本需要15分钟.
我不知道我做错了什么或者没有在shell脚本中使用正确的运算符.
编辑:我不能使用awk,因为没有一个模式来处理该行
我试着评论"echo $ out">>"$ outFileName",但它并没有变得更好.我认为问题是$ {line:106:61}操作.有什么建议?
谢谢你的帮助.
我正在编写一个活动来列出数据库中的一堆项目,并显示一个包含数量的附加列.我实现了一个ArrayAdapter来显示我的自定义布局.以下是适配器最重要部分的代码:
static class ViewHolder {
protected TextView text;
protected EditText editText;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rowquantitylayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.editText = (EditText) view.findViewById(R.id.editText);
viewHolder.editText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Log.i(TAG, "Editable:" + s.toString());
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void …Run Code Online (Sandbox Code Playgroud)