Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
e787d94b
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e787d94b
编写于
11月 29, 2011
作者:
A
Alex Tkachman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
++/-- performance optimization
上级
4fc41f4a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
280 addition
and
4 deletion
+280
-4
compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
...kend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
+10
-2
compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java
...ler/backend/src/org/jetbrains/jet/codegen/StackValue.java
+48
-0
compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java
...d/src/org/jetbrains/jet/codegen/intrinsics/Increment.java
+1
-2
examples/src/benchmarks/BinaryTrees.java
examples/src/benchmarks/BinaryTrees.java
+74
-0
examples/src/benchmarks/BinaryTrees.kt
examples/src/benchmarks/BinaryTrees.kt
+52
-0
examples/src/benchmarks/Quicksort.java
examples/src/benchmarks/Quicksort.java
+48
-0
examples/src/benchmarks/Quicksort.kt
examples/src/benchmarks/Quicksort.kt
+47
-0
未找到文件。
compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
浏览文件 @
e787d94b
...
...
@@ -1905,8 +1905,16 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
DeclarationDescriptor
cls
=
op
.
getContainingDeclaration
();
if
(
isNumberPrimitive
(
cls
)
&&
(
op
.
getName
().
equals
(
"inc"
)
||
op
.
getName
().
equals
(
"dec"
)))
{
receiver
.
put
(
receiver
.
type
,
v
);
gen
(
expression
.
getBaseExpression
(),
asmType
);
// old value
generateIncrement
(
op
,
asmType
,
expression
.
getBaseExpression
(),
receiver
);
// increment in-place
JetExpression
operand
=
expression
.
getBaseExpression
();
if
(
operand
instanceof
JetReferenceExpression
)
{
final
int
index
=
indexOfLocal
((
JetReferenceExpression
)
operand
);
if
(
index
>=
0
&&
JetTypeMapper
.
isIntPrimitive
(
asmType
))
{
int
increment
=
op
.
getName
().
equals
(
"inc"
)
?
1
:
-
1
;
return
StackValue
.
postIncrement
(
index
,
increment
);
}
}
gen
(
operand
,
asmType
);
// old value
generateIncrement
(
op
,
asmType
,
operand
,
receiver
);
// increment in-place
return
StackValue
.
onStack
(
asmType
);
// old value
}
}
...
...
compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java
浏览文件 @
e787d94b
...
...
@@ -256,6 +256,14 @@ public abstract class StackValue {
return
new
ThisOuter
(
codegen
,
descriptor
);
}
public
static
StackValue
postIncrement
(
int
index
,
int
increment
)
{
return
new
PostIncrement
(
index
,
increment
);
}
public
static
StackValue
preIncrement
(
int
index
,
int
increment
)
{
return
new
PreIncrement
(
index
,
increment
);
}
private
static
class
None
extends
StackValue
{
public
static
None
INSTANCE
=
new
None
();
private
None
()
{
...
...
@@ -963,4 +971,44 @@ public abstract class StackValue {
codegen
.
generateThisOrOuter
(
descriptor
);
}
}
private
static
class
PostIncrement
extends
StackValue
{
private
int
index
;
private
int
increment
;
public
PostIncrement
(
int
index
,
int
increment
)
{
super
(
Type
.
INT_TYPE
);
this
.
index
=
index
;
this
.
increment
=
increment
;
}
@Override
public
void
put
(
Type
type
,
InstructionAdapter
v
)
{
if
(!
type
.
equals
(
Type
.
VOID_TYPE
))
{
v
.
load
(
index
,
Type
.
INT_TYPE
);
coerce
(
type
,
v
);
}
v
.
iinc
(
index
,
increment
);
}
}
private
static
class
PreIncrement
extends
StackValue
{
private
int
index
;
private
int
increment
;
public
PreIncrement
(
int
index
,
int
increment
)
{
super
(
Type
.
INT_TYPE
);
this
.
index
=
index
;
this
.
increment
=
increment
;
}
@Override
public
void
put
(
Type
type
,
InstructionAdapter
v
)
{
v
.
iinc
(
index
,
increment
);
if
(!
type
.
equals
(
Type
.
VOID_TYPE
))
{
v
.
load
(
index
,
Type
.
INT_TYPE
);
coerce
(
type
,
v
);
}
}
}
}
compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java
浏览文件 @
e787d94b
...
...
@@ -31,8 +31,7 @@ public class Increment implements IntrinsicMethod {
if
(
operand
instanceof
JetReferenceExpression
)
{
final
int
index
=
codegen
.
indexOfLocal
((
JetReferenceExpression
)
operand
);
if
(
index
>=
0
&&
JetTypeMapper
.
isIntPrimitive
(
expectedType
))
{
v
.
iinc
(
index
,
myDelta
);
return
StackValue
.
local
(
index
,
expectedType
);
return
StackValue
.
preIncrement
(
index
,
myDelta
);
}
}
StackValue
value
=
codegen
.
genQualified
(
receiver
,
operand
);
...
...
examples/src/benchmarks/BinaryTrees.java
0 → 100644
浏览文件 @
e787d94b
public
class
BinaryTrees
{
private
final
static
int
minDepth
=
4
;
public
static
void
main
(
String
[]
args
){
final
long
millis
=
System
.
currentTimeMillis
();
int
n
=
20
;
if
(
args
.
length
>
0
)
n
=
Integer
.
parseInt
(
args
[
0
]);
int
maxDepth
=
(
minDepth
+
2
>
n
)
?
minDepth
+
2
:
n
;
int
stretchDepth
=
maxDepth
+
1
;
int
check
=
(
TreeNode
.
bottomUpTree
(
0
,
stretchDepth
)).
itemCheck
();
System
.
out
.
println
(
"stretch tree of depth "
+
stretchDepth
+
"\t check: "
+
check
);
TreeNode
longLivedTree
=
TreeNode
.
bottomUpTree
(
0
,
maxDepth
);
for
(
int
depth
=
minDepth
;
depth
<=
maxDepth
;
depth
+=
2
){
int
iterations
=
1
<<
(
maxDepth
-
depth
+
minDepth
);
check
=
0
;
for
(
int
i
=
1
;
i
<=
iterations
;
i
++){
check
+=
(
TreeNode
.
bottomUpTree
(
i
,
depth
)).
itemCheck
();
check
+=
(
TreeNode
.
bottomUpTree
(-
i
,
depth
)).
itemCheck
();
}
System
.
out
.
println
((
iterations
*
2
)
+
"\t trees of depth "
+
depth
+
"\t check: "
+
check
);
}
System
.
out
.
println
(
"long lived tree of depth "
+
maxDepth
+
"\t check: "
+
longLivedTree
.
itemCheck
());
long
total
=
System
.
currentTimeMillis
()
-
millis
;
System
.
out
.
println
(
"[Binary Trees-"
+
System
.
getProperty
(
"project.name"
)+
" Benchmark Result: "
+
total
+
"]"
);
}
private
static
class
TreeNode
{
private
TreeNode
left
,
right
;
private
int
item
;
TreeNode
(
int
item
){
this
.
item
=
item
;
}
private
static
TreeNode
bottomUpTree
(
int
item
,
int
depth
){
if
(
depth
>
0
){
return
new
TreeNode
(
bottomUpTree
(
2
*
item
-
1
,
depth
-
1
)
,
bottomUpTree
(
2
*
item
,
depth
-
1
)
,
item
);
}
else
{
return
new
TreeNode
(
item
);
}
}
TreeNode
(
TreeNode
left
,
TreeNode
right
,
int
item
){
this
.
left
=
left
;
this
.
right
=
right
;
this
.
item
=
item
;
}
private
int
itemCheck
(){
// if necessary deallocate here
if
(
left
==
null
)
return
item
;
else
{
return
item
+
left
.
itemCheck
()
-
right
.
itemCheck
();
}
}
}
}
examples/src/benchmarks/BinaryTrees.kt
0 → 100644
浏览文件 @
e787d94b
val
minDepth
=
4
fun
main
(
args
:
Array
<
String
>)
{
val
millis
=
System
.
currentTimeMillis
()
val
n
=
if
(
args
.
size
>
0
)
Integer
.
parseInt
(
args
[
0
])
else
20
;
val
maxDepth
=
if
(
minDepth
+
2
>
n
)
minDepth
+
2
else
n
val
stretchDepth
=
maxDepth
+
1
var
check
=
bottomUpTree
(
0
,
stretchDepth
).
itemCheck
()
System
.
out
?.
println
(
"stretch tree of depth "
+
stretchDepth
+
"\t check: "
+
check
);
val
longLivedTree
=
bottomUpTree
(
0
,
maxDepth
);
var
depth
=
minDepth
while
(
depth
<=
maxDepth
){
val
iterations
=
1
shl
(
maxDepth
-
depth
+
minDepth
)
check
=
0
for
(
i
in
1
..
iterations
){
check
+=
bottomUpTree
(
i
,
depth
).
itemCheck
()
check
+=
bottomUpTree
(-
i
,
depth
).
itemCheck
()
}
System
.
out
?.
println
(
"${iterations*2}\t trees of depth $depth\t check: $check"
)
depth
+=
2
}
System
.
out
?.
println
(
"long lived tree of depth "
+
maxDepth
+
"\t check: "
+
longLivedTree
.
itemCheck
());
val
total
=
System
.
currentTimeMillis
()
-
millis
System
.
out
?.
println
(
"[Binary Trees-"
+
System
.
getProperty
(
"project.name"
)
+
" Benchmark Result: "
+
total
+
"]"
);
}
fun
bottomUpTree
(
item
:
Int
,
depth
:
Int
)
:
TreeNode
=
if
(
depth
>
0
){
TreeNode
(
item
,
bottomUpTree
(
2
*
item-1
,
depth-1
),
bottomUpTree
(
2
*
item
,
depth-1
))
}
else
{
TreeNode
(
item
,
null
,
null
)
}
class
TreeNode
(
val
item
:
Int
,
val
left
:
TreeNode
?,
val
right
:
TreeNode
?)
{
fun
itemCheck
()
:
Int
{
var
res
=
item
if
(
left
!=
null
)
res
+=
left
.
itemCheck
()
if
(
right
!=
null
)
res
-=
right
.
itemCheck
()
return
res
}
}
examples/src/benchmarks/Quicksort.java
0 → 100644
浏览文件 @
e787d94b
public
class
Quicksort
{
public
static
void
swap
(
int
[]
a
,
int
i
,
int
j
)
{
int
temp
=
a
[
i
];
a
[
i
]
=
a
[
j
];
a
[
j
]
=
temp
;
}
public
static
void
quicksort
(
int
[]
a
,
int
L
,
int
R
)
{
int
m
=
a
[(
L
+
R
)
/
2
];
int
i
=
L
;
int
j
=
R
;
while
(
i
<=
j
)
{
while
(
a
[
i
]
<
m
)
i
++;
while
(
a
[
j
]
>
m
)
j
--;
if
(
i
<=
j
)
{
swap
(
a
,
i
++,
j
--);
}
}
if
(
L
<
j
)
quicksort
(
a
,
L
,
j
);
if
(
R
>
i
)
quicksort
(
a
,
i
,
R
);
}
public
static
void
quicksort
(
int
[]
a
)
{
quicksort
(
a
,
0
,
a
.
length
-
1
);
}
public
static
void
main
(
String
[]
args
)
{
// Sample data
int
[]
a
=
new
int
[
100000000
];
for
(
int
i
=
0
;
i
<
a
.
length
;
i
++)
{
a
[
i
]
=
i
*
3
/
2
+
1
;
if
(
i
%
3
==
0
)
a
[
i
]
=
-
a
[
i
];
}
long
start
=
System
.
currentTimeMillis
();
quicksort
(
a
);
long
total
=
System
.
currentTimeMillis
()
-
start
;
System
.
out
.
println
(
"[Quicksort-"
+
System
.
getProperty
(
"project.name"
)+
" Benchmark Result: "
+
total
+
"]"
);
}
}
\ No newline at end of file
examples/src/benchmarks/Quicksort.kt
0 → 100644
浏览文件 @
e787d94b
namespace
quicksort
fun
IntArray
.
swap
(
i
:
Int
,
j
:
Int
)
{
val
temp
=
this
[
i
]
this
[
i
]
=
this
[
j
]
this
[
j
]
=
temp
}
fun
IntArray
.
quicksort
()
=
quicksort
(
0
,
size-1
)
fun
IntArray
.
quicksort
(
L
:
Int
,
R
:
Int
)
{
val
m
=
this
[(
L
+
R
)
/
2
]
var
i
=
L
var
j
=
R
while
(
i
<=
j
)
{
while
(
this
[
i
]
<
m
)
i
++
while
(
this
[
j
]
>
m
)
j--
if
(
i
<=
j
)
{
KT-5
swap
(
i
++,
j--
)
}
}
if
(
L
<
j
)
quicksort
(
L
,
j
)
if
(
R
>
i
)
quicksort
(
i
,
R
)
}
fun
main
(
array
:
Array
<
String
>)
{
val
a
=
IntArray
(
100000000
)
var
i
=
0
val
len
=
a
.
size
while
(
i
<
len
)
{
a
[
i
]
=
i
*
3
/
2
+
1
if
(
i
%
3
==
0
)
a
[
i
]
=
-
a
[
i
]
i
++
}
val
start
=
System
.
currentTimeMillis
()
a
.
quicksort
()
val
total
=
System
.
currentTimeMillis
()
-
start
System
.
out
?.
println
(
"[Quicksort-"
+
System
.
getProperty
(
"project.name"
)+
" Benchmark Result: "
+
total
+
"]"
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录